+ Reply to Thread
Results 1 to 7 of 7

Looking for VBA code to Put values in Column A and B when Column C is Not Empty

Hybrid View

bjnockle Looking for VBA code to Put... 03-20-2022, 01:13 PM
JohnTopley Re: Looking for VBA code to... 03-20-2022, 01:59 PM
bjnockle Re: Looking for VBA code to... 03-21-2022, 01:34 PM
jolivanes Re: Looking for VBA code to... 03-20-2022, 02:03 PM
bjnockle Re: Looking for VBA code to... 03-21-2022, 01:36 PM
jolivanes Re: Looking for VBA code to... 03-21-2022, 03:10 PM
JohnTopley Re: Looking for VBA code to... 03-21-2022, 05:37 PM
  1. #1
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,012

    Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    Looking for VBA code to put values in Column A and B when Column C is Not Empty. Reason for looking for VBA code is that the data set is 362656 and when a formula is used, the Excel Workbook is crashing. Formula works fine but it is crashing the Excel Workbook or getting stuck.

    For example, column C2:C4 (Sales Year column) are not empty (C2=1999, C3=2000 and C4=2001), the VBA code should put in A3= 1st S and A4= 1st S and leave A2 = 1st S since A2 has a value already. Also, the VBA code should put in B3= 01103 and B4= 01103 and leave B2 = 01103 since B2 has a value already. The VBA code should do this for column A2:A500,000 and

    ****Desired solution sample is in F2:G25
    ****VBA Code solution should put values in A2:B362656. Please write the VBA to go beyond 362656 rows in case additional data is entered.

    See sample file.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,898

    Re: Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    Sub JT_V01()
    
    Dim arr
    arr = [A1].CurrentRegion
    
    Application.ScreenUpdating = False
    
    For i = 2 To UBound(arr, 1)
        If arr(i, 1) = "" Then arr(i, 1) = arr(i - 1, 1): arr(i, 2) = arr(i - 1, 2)
    Next i
    
    [f1].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
    
    Application.ScreenUpdating = True
    
    
    End Sub
    Attached Files Attached Files
    Last edited by JohnTopley; 03-20-2022 at 05:52 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,012

    Re: Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    JohnTopley: Outstanding solution. Works like a charm, JohnTopley. Thanks a lot.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    You can try this on a copy of your workbook.
    The empty looking cells in Column A are not empty. In the attachment anyway
    Sub Maybe()
    Dim lr As Long
    lr = Cells(Rows.Count, 3).End(xlUp).Row
    With Range("B2:B" & lr).SpecialCells(xlCellTypeBlanks)
            .FormulaR1C1 = "=R[-1]C"
            .Offset(, -1).FormulaR1C1 = "=R[-1]C"
    End With
    Range("A2:B" & lr).Value = Range("A2:B" & lr).Value
    End Sub

  5. #5
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,012

    Re: Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    jolivanes: Excellent solution, jolivanes. Works like a charm.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    Thank you for letting us know that all is well now.

    Good luck

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,898

    Re: Looking for VBA code to Put values in Column A and B when Column C is Not Empty

    Thank you for the feedback and rep: much appreciated.

+ 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. VBA Code to Paste Values a Table Column Based on Values in Another Column
    By demiwen12 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-20-2020, 05:39 PM
  2. [SOLVED] Check all rows in UsedRange - if column A is not empty do stuff with column A and B values
    By Arnold Layne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-14-2020, 04:28 PM
  3. Next empty column code help
    By JBDC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-05-2015, 03:06 PM
  4. [SOLVED] Copy and paste values in column range into first empty column to the left
    By gbatz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2014, 06:59 PM
  5. [SOLVED] Move Values of a Column and Delete the Empty Column
    By aviatecar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-09-2014, 03:27 PM
  6. [SOLVED] Select Case Code for Column A Values to Populate Results in Column B in Same Row
    By excelforumkeys in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2014, 05:22 PM
  7. [SOLVED] need vba code to compare two column get result of common values of both column
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2013, 05:42 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