Loop to check if cell value starts from digit and copy and offset the cells

fotodj

New Member
Joined
Jul 19, 2014
Messages
27
I am trying to make a VBA loop to identify if first character in cell A starts from digit and if yes, copy cell value from column B in this row to column C and offset it one row up....

10-6-2022 9-24-37 PM.jpg


I guess this would be the backbone of the code, back I need help with identifying if first character in cell A is a digit and then use proper code to copy cell B and offset it:

VBA Code:
  Sub TestForDigit()
Dim x As Integer
Dim c As Range

x = 0

For Each c In Range("A1:A100")
   'if c.Value = (if starts from digit)
    If c.Value = (starts from digit)
    Then (copy cell in col B to col C and offset it one cell up)
        
    End If
Next c


End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Like this:
VBA Code:
Option Explicit
Sub test()
Dim lr&, cell As Range
lr = Cells(Rows.Count, "A").End(xlUp).Row
Range("C1:C100000").ClearContents
For Each cell In Range("A2:A" & lr)
    If IsNumeric(Left(cell, 1)) Then cell.Offset(-1, 2).Value = cell.Offset(, 1).Value
Next
End Sub
 
Upvote 0
Solution
@fotodj
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

If you are interested, you could also do the whole column at once rather than looping a row at a time.

VBA Code:
Sub Test_For_Digit()
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    .Offset(-1, 2).Value = Evaluate("if(isnumber(left(" & .Address & ",1)+0)," & .Offset(, 1).Address & ","""")")
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,868
Messages
6,122,005
Members
449,059
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top