+ Reply to Thread
Results 1 to 4 of 4

change the cell number with correct number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-06-2014
    Location
    iran
    MS-Off Ver
    2016
    Posts
    110

    change the cell number with correct number

    Hi
    I want to find exact cell that belongs to each utmx in sheet and copy it to entire column in utmx name sheet if the cell is not empty and replace it .(column l)
    b1-------------->b2-------------->c
    thanks
    Last edited by fakhteh; 04-03-2021 at 07:31 AM.

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: change the cell number with correct number

    Assuming your main sheet is called "Sheet1", try this code

    Sub chmgcell()
    'Change Sheet1 to name of your main sheet
    Dim cel, rng As Range
    Dim lr, lrn As Long
    lr = Sheets("Sheet1").Cells(Rows.Count, 3).End(xlUp).Row
    Set rng = Sheets("Sheet1").Range("C2:C" & lr)
    For Each cel In rng
        If Not IsEmpty(cel.Offset(0, 7).Value) Then
            lrn = Sheets(Trim(cel)).Cells(Rows.Count, 7).End(xlUp).Row
            Sheets(Trim(cel)).Range("L2:L" & lrn).Value = cel.Offset(0, 7).Value
        End If
    Next cel
    
    End Sub
    Last edited by maniacb; 04-03-2021 at 08:49 AM. Reason: added code to account for empty values

  3. #3
    Forum Contributor
    Join Date
    08-06-2014
    Location
    iran
    MS-Off Ver
    2016
    Posts
    110

    Re: change the cell number with correct number

    hi again
    first of all I appreciate your help
    something is wrong so I attach an excel file to clarify it
    for example :you can see sheet2 and 238458 in excel file
    so I want to change and correct 238458 --to-----> 238458- with j25 in sheet2
    ((please do this correct just in 238458 and do not open and create another sheet like 238458-))
    as I mentioned before I have many sheets for changing with finding dependent cell from sheet2
    I run your code and the error is shown in image that I attached
    thank you
    Attached Images Attached Images
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: change the cell number with correct number

    Give this a try

    Sub chmgcell()
    'Change Sheet2 to name of your main sheet
    Dim cel, rng As Range
    Dim lr, lrn As Long
    lr = Sheets("Sheet2").Cells(Rows.Count, 3).End(xlUp).Row
    Set rng = Sheets("Sheet2").Range("C2:C" & lr)
    For Each cel In rng
        If Not IsEmpty(cel.Offset(0, 7).Value) Then
        On Error Resume Next
            lrn = Sheets(Trim(cel)).Cells(Rows.Count, 7).End(xlUp).Row
            If lrn <> 0 Then
                Sheets(Trim(cel)).Range("L2:L" & lrn).Value = cel.Offset(0, 7).Value
                lrn = 0
            End If
            On Error GoTo 0
        End If
    Next cel
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-25-2020, 09:00 AM
  2. [SOLVED] How to correctly display the correct calculated number and mask away exceeding number
    By Andrew88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-06-2017, 07:44 AM
  3. [SOLVED] Macro to change number to number in another cell
    By Anarchus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2017, 09:13 PM
  4. Replies: 10
    Last Post: 10-21-2015, 09:06 PM
  5. Correct text number to excel number format?
    By domgilberto in forum Excel General
    Replies: 9
    Last Post: 09-11-2015, 05:39 PM
  6. [SOLVED] Varying number in one cell, to change to a set number in another
    By Geoffo123 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 12-11-2012, 08:36 PM
  7. Replies: 1
    Last Post: 06-06-2005, 06:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1