+ Reply to Thread
Results 1 to 6 of 6

copying vaules from and adjacent cell based on another

  1. #1
    Registered User
    Join Date
    11-12-2022
    Location
    Ontario
    MS-Off Ver
    Office 365 2021
    Posts
    3

    copying vaules from and adjacent cell based on another

    Hi all,
    I am new to VBA so please excuse any or silly errors.

    I am trying to step thru the cells in a selected range in a column.

    I want to read the value of the first cell Rng(r) and if it contains the text string "total" then copy the value of another cell, 1 up and 1 to the right of that cell, to the cell to the right of the cell Rng(r).
    If the text string does not contain "total" then do nothing and evaluate the next in the range using r=r+1.

    here is the code, I am strugling to get the if statement to work, and the syntax.

    Sub copyDescription()
    'Display a messagebox based on the response
    If MsgBox("Make sure the range is selected and the cells have valid values. Do you wish to continue? ", vbYesNo) = vbYes Then
    'Sub routine for copying descriptions
    Dim Rng As Range
    Dim maxRows, r As Integer
    Set Rng = Selection
    maxRows = Rng.Rows.Count
    r = 1
    Do While r <= maxRows
    if (IsNumber(Search("total", Rng(r)),ActiveCell.offset(0,1)= ActiveCell.offset(-1,1),""))
    On Error Resume Next
    End If
    r = r + 1
    Loop
    MsgBox "values entered"
    Else
    MsgBox "Process aborted" 'Process stopped message
    End If

    End Sub
    Attached Files Attached Files
    Last edited by PaulD21; 11-12-2022 at 11:03 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: copying vaules from and adjacent cell based on another

    Hi Paul...
    Welcome to forum...See Top Yellow Banner regarding sample file with before|after expected output
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this ...


    According to the attachment an Excel basics VBA demonstration as a beginner starter :

    PHP Code: 
    Sub Demo1()
            
    Dim Rc As Range
        With Sheet2
    .Range("D10"Sheet2.[C8].End(xlDown)(02))
            If 
    Application.CountBlank(.CellsThen For Each Rc In .SpecialCells(4): Rc Rc(0): Next
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 11-12-2022 at 05:28 PM. Reason: optimization ...

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb ... or this !


    According to the attachment the direct beginner formula VBA variation :

    PHP Code: 
    Sub Demo1v()
        
    With Sheet2.Range("D10"Sheet2.[C8].End(xlDown)(02))
            .
    Value = .Parent.Evaluate("=IF(" & .Address "=0," & .Offset(-1).Address "," & .Address ")")
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    11-12-2022
    Location
    Ontario
    MS-Off Ver
    Office 365 2021
    Posts
    3

    Re: copying vaules from and adjacent cell based on another

    Thanks,
    These work, now I need to inspect the code to understand why. But I guess that's part of the learning journey.

  6. #6
    Registered User
    Join Date
    11-12-2022
    Location
    Ontario
    MS-Off Ver
    Office 365 2021
    Posts
    3

    Re: copying vaules from and adjacent cell based on another

    I am trying to see what additions would be to the code if I wanted to copy the value for the rest of the cells in the row,
    Specially the Revision, Material, Thickness, Finish, Process, and Vendor columns.
    I'm still not totally clear on the syntax used here.

+ 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. Copying Adjacent Cell to it's Duplicate.
    By JEBianchi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-19-2018, 05:41 AM
  2. [SOLVED] VBA ComboBox Different Default Vaules Based on Time of Year
    By heanhan in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-23-2016, 09:46 AM
  3. change col A vaules based on odd col b values
    By sbktex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2014, 04:36 AM
  4. [SOLVED] Copying today's date into cell when multiple data is entered into adjacent cell
    By SChapman in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-16-2013, 04:12 PM
  5. [SOLVED] Copying adjacent cell over from different worksheet
    By dlamberth in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-14-2013, 03:44 PM
  6. generate stmt based on tables vaules
    By kaffal in forum Excel General
    Replies: 1
    Last Post: 01-18-2009, 04:38 PM
  7. [SOLVED] copying data to an adjacent cell
    By Paul K. in forum Excel General
    Replies: 2
    Last Post: 10-05-2005, 11:05 AM

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