VBA learner ITG
Active Member
- Joined
- Apr 18, 2017
- Messages
- 272
- Office Version
- 365
- Platform
- Windows
- MacOS
Good afternoon,
The below code only adds the worksheet name to column cell range D2-D5 regardless of what text is in cells D2-D5.
Can I get your guidance to amend the code that if there is a word "Category" or "Store" in column D that it adds the worksheet Name and _with the cell value which is either going to be "Category" "Store" instead of it only being applicable to cells D2-D5 per the below code?
e.g:
Sheet1_Category
Sheet1_Store
The below code only adds the worksheet name to column cell range D2-D5 regardless of what text is in cells D2-D5.
Can I get your guidance to amend the code that if there is a word "Category" or "Store" in column D that it adds the worksheet Name and _with the cell value which is either going to be "Category" "Store" instead of it only being applicable to cells D2-D5 per the below code?
e.g:
Sheet1_Category
Sheet1_Store
Code:
ws.Range("D2").Value = ws.Name & "_" & ws.Range("D2").Value
ws.Range("D3").Value = ws.Name & "_" & ws.Range("D3").Value
ws.Range("D4").Value = ws.Name & "_" & ws.Range("D4").Value
ws.Range("D5").Value = ws.Name & "_" & ws.Range("D5").Value
DoEvents
ws.Copy
ActiveWorkbook.SaveAs sheetDirectory & Application.PathSeparator & ws.Name & "_" & wbName
DoEvents
ActiveWorkbook.Close
validWs = True
End If
Next ws
Last edited: