-
Sep 29th, 2014, 09:01 AM
#1
Thread Starter
Member
[RESOLVED] Insert a cell based on condition
Hi. I want to insert a cell based on what is found in column K.
Here is my code, not sure how to tweak it.
Code:
Dim ws As Worksheet
Dim LastRow As Long
Dim j As Long
Set ws = ActiveSheet
LastRow = ws.Range("K" & Rows.Count).End(xlUp).Row
For j = LastRow To 1 Step -1
If Left(ws.Range("K" & j).Value, 2) = "PF" Then
ws.Cells("K" & j).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
End If
Next j
also, i would kind of like if the cell was inserted with some text.
Thanks alot.
-
Sep 29th, 2014, 10:42 AM
#2
Re: Insert a cell based on condition
Change this:
Code:
ws.Cells("K" & j).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
to this:
Code:
ws.Range("K" & j).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
if you want to move all cells in that row from K on to the right.
What text do you want added?
-
Sep 29th, 2014, 11:26 AM
#3
Thread Starter
Member
Re: Insert a cell based on condition
The test would say "finance."
Thanks!
-
Sep 29th, 2014, 12:09 PM
#4
Re: Insert a cell based on condition
then add:
Code:
ws.range("k" & j).value="finance"
after the line which inserts a blank cell.
-
Sep 29th, 2014, 01:38 PM
#5
Thread Starter
Member
Re: Insert a cell based on condition
thanks once again vbfbryce!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|