Insert Value into Cell

acemecca

New Member
Joined
Sep 14, 2011
Messages
19
Greetings:

I am new to VBA and need assistance badly. I am working a spreadsheet where I need to locate the number '3' in column B and populate the number '2' in the cell above it in column B.

Please advise...thanks!
 
Maybe this

Code:
Sub b()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    If Range("B" & i).Value = 2 Then Range("C" & i).Formula = Range("C2").Formula
Next i
End Sub
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Maybe this

Code:
Sub b()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    If Range("B" & i).Value = 2 Then Range("C" & i).Formula = Range("C2").Formula
Next i
End Sub

Greetings:

I am using the following to locate a number and populate another, but only if an open row is available above the row...can you assist?

Macro to insert value after locating other value (locate 3 and populate 2)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Code:<o:p></o:p>
Sub find3pop2()<o:p></o:p>
Dim LR As Long, i As Long<o:p></o:p>
LR = Range("B" & Rows.Count).End(xlUp).Row<o:p></o:p>
For i = 2 To LR<o:p></o:p>
If Range("B" & i).Value = 3 Then Range("B" & i - 1).Value = 2<o:p></o:p>
Next i<o:p></o:p>
End Sub<o:p></o:p>

Macro to insert value after locating other value (locate 2 and populate 1)<o:p></o:p>
Code:<o:p></o:p>
Sub find2pop1()<o:p></o:p>
Dim LR As Long, i As Long<o:p></o:p>
LR = Range("B" & Rows.Count).End(xlUp).Row<o:p></o:p>
For i = 2 To LR<o:p></o:p>
If Range("B" & i).Value = 2 Then Range("B" & i - 1).Value = 1<o:p></o:p>
Next i<o:p></o:p>
End Sub<o:p></o:p>
 
Upvote 0
Try like this

Rich (BB code):
Sub find3pop2()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LR
If Range("B" & i).Value = 3 And Range("B" & i - 1).Value = "" Then Range("B" & i - 1).Value = 2
Next i
End Sub
 
Upvote 0
Actually, I have one more thing before I can start filling my template....how can I copy a formula (ie. located in C2) and populate or paste that in column C where the number 2 is present in column B? I hope I explained it right. I will use this for another formula to apply to column B's number 1 entries....thanks!

Thanks...the adjustment worked for the numbering issue...I am trying to apply the formula in my cell C3 to all the items listed as level 2....I also want a code for the formula in cell C2 to all the items on level 1....please see attached...

http://smg.photobucket.com/albums/v716/acemecca/?action=view&current=ScreenShot018.jpg
 
Upvote 0

Forum statistics

Threads
1,223,923
Messages
6,175,388
Members
452,640
Latest member
steveridge

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