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!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try like this

Code:
Sub b()
Dim Found As Range
Set Found = Columns("B").Find(what:=3, LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then Found.Offset(-1).Value = 2
End Sub
 
Upvote 0
how do you make the macro repeat for the entire spreadsheet? I worked on one line but not the entire spreadsheet...thanks!
 
Upvote 0
Try

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 = 3 Then Range("B" & i - 1).lvalue = 2
Next i
End Sub
 
Upvote 0
I am getting a run-time error 438...i deleted the first macro and this is the error i am receiving...you are helping me a GREAT deal...thanks for the assistance...looking forward to your reply!
 
Upvote 0
Sorry, I had a typo

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 = 3 Then Range("B" & i - 1).Value = 2
Next i
End Sub
 
Upvote 0
PERFECT....and what do I substitute for locating the number 2 and populating the number 1 in the same spreadsheet??
 
Upvote 0
That would be

Rich (BB 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("B" & i - 1).Value = 1
Next i
End Sub
 
Upvote 0
Peter - u are a lifesaver....so far so good on my build....I will bug you later but this is a great start....thanks again!
 
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!
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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