Edit Specific Range if Cell Value is True

temerson

New Member
Joined
Apr 22, 2019
Messages
39
Hello,

I have the code below:

Sub editrange

Dim nLastRow, i As Integer

Set wbCurrent = ActiveWorkbook


Set WS = wbCurrent.Worksheets("Sheet1")
nLastRow = WS.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = nLastRow To 13 Step -1
If InStr(1, WS.Cells(i, 7).Value, "Blue", vbTextCompare) > 0 Then
Else
this is where i want to put in a value in a specific range (edit all cells in row(s) that has a "b" in row 2)
End If

Next i

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi, I'm following your code to try answer your cuestions

Please use this example or put your own, for help us to understand your questions

Also, answer the question, that you see like comments inside the code

Book1
ABCDEFGHIJ
1
2Key1 Number 1 Meaning 1 Key2 Number 2 Meaning 2Key3 Number 3 Meaning 3Key4
3Avaya54366Tabel443948Greenbebe
4Avaya54476Tabel443958DPAMax@gmailvzla
5DPAAnna@gmailAvaya56466Tabel453948Chat
6Tabel444948Avaya54466Redbetacaroteno
7Avaya54466Tabel443948DPATh@gmailtambien
8Chat121312Avaya54466Tabel443948DPA
9Avaya54366Tabel443948Yellowbebe
10Avaya54476Tabel443958DPAMax@gmailvzla
11DPAAnna@gmailAvaya56466Tabel453948Chat
12Tabel444948Avaya54466Bluebetacaroteno
13Avaya54466Tabel443948DPATh@gmailtambien
14Chat121312Avaya54466Tabel443948DPA
15Avaya54366Tabel443948Bluebebe
16Avaya54476Tabel443958DPAMax@gmailvzla
17DPAAnna@gmailAvaya56466Tabel453948Chat
18Tabel444948Avaya54466Bluebetacaroteno
19Avaya54466Tabel443948DPATh@gmailtambien
20Chat121312Avaya54466Tabel443948DPA
21Avaya54366Tabel443948Bluebebe
22Avaya54476Tabel443958DPAMax@gmailvzla
23DPAAnna@gmailAvaya56466Tabel453948Chat
24Tabel444948Avaya54466Bluebetacaroteno
25Avaya54466Tabel443948DPATh@gmailtambien
26Chat121312Avaya54466Tabel443948DPA
temerson


VBA Code:
Option Explicit
'Refers to temerson sheet
'With this code, you are checking the last 13 cells in column G
'Tell me something, what condition I will take, to put the value in every cell in row 2?
'I ask, because you need this inside the Else statement.
'I'm sorry, It just doesn't make sense, to evaluate this inside Else clause,
'as it would repeat in every cycle

Sub editrange()

Dim nLastRow, i As Integer
Dim wbCurrent As Workbook
Dim ws As Worksheet

Set wbCurrent = ActiveWorkbook
Set ws = wbCurrent.Worksheets("temerson")
nLastRow = ws.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = nLastRow To 13 Step -1
If InStr(1, ws.Cells(i, 7).Value, "Blue", 1) > 0 Then
MsgBox "Found Blue in " & Cells(i, 7).Address, vbInformation, "Mikel ERP by htorres"
Else
'this is where i want to put in a value in a specific range (edit all cells in row(s) that has a "b" in row 2)
End If

Next i
End Sub
 
Upvote 0
Hello,

I think I explained my goal incorrectly. I have attached an example.

'the code below searches "Blue" column G all the way up to row 13. I don't want rows 1-12 to be searched.
nLastRow = ws.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = nLastRow To 13 Step -1
If InStr(1, ws.Cells(i, 7).Value, "Blue", 1) > 0 Then

'I should have put the bold sentence below above the Else. Basically, if "Blue" is found, I would like to edit cells in that row if also B is found in row 2 starting with column V

Else
'this is where i want to put in a value in a specific range (edit all cells in row(s) that has a "b" in row 2)
End If

If it does not find Blue, then nothing happens.
 

Attachments

  • Color Code.jpg
    Color Code.jpg
    23.8 KB · Views: 10
Upvote 0
Thanks a lot, but please try prepare a data example using add-in specifically for this and it can be found here XL2BB
If necessary, pay attention to this post XL2BB 2 Square
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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