String problem simpler explanation

sueandco

New Member
Joined
Oct 19, 2002
Messages
31
Hi
I need to put a value in cell Q6 if it is empty
If not then put this value in Q7
or loop until i find an empty one in the Q column. This is to be used as part of a macro.

Any help welcome thanks
sue
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I think I read an earlier post where you were looking to merge strings?

So lets say you want to merge Sheet1 A1 with " dated " and Sheet1 B1 and paste this into the next blank cell in Q from row 6 down to 100 in Sheet2

Sub BLANKLOOP()

PASTECELL = Sheets("sheet1").range("A1") & " dated " & Sheets("Sheet1").range("B1")

DATA = Sheets("sheet2").range("Q6:Q100")
CROW = 6

For Each LDATA in DATA

If LDATA = "" THEN
Sheets("Sheet2").Range("Q" & CROW) = PASTECELL
END IF

CROW = CROW + 1

NEXT LDATA

Does this get you started?
 
Upvote 0
Sue

Assuming what you need is to find the last free cell in Col Q ie no gaps in Col data, Try:-
Lastrow = Range("Q65000").End(xlUp).row(this finds the last cell in col Q of your existing data)
Targetcell = "Q"&lastrow+1
Range(targetcell).value = whatever you want to input
 
Upvote 0
Hi lasw
Not quite.
a string generated by a macro is inserted into N25, I want to paste this into cell Q6 when i execute th macro again i want the results put into Q6, if the result is Null then Q6 stays as it is, If the result is another string and Q6 is Full (ie the first string was not null) then the result will go into Q7.and so on down the Q column.
Hope this explanation is OK
thanks
Sue
 
Upvote 0
On 2002-10-30 05:26, sueandco wrote:
Hi lasw
Not quite.
a string generated by a macro is inserted into N25, I want to paste this into cell Q6 when i execute th macro again i want the results put into Q6, if the result is Null then Q6 stays as it is, If the result is another string and Q6 is Full (ie the first string was not null) then the result will go into Q7.and so on down the Q column.
Hope this explanation is OK
thanks
Sue


PASTECELL = Range("N25")

DATA = Range("Q6:Q100")
CROW = 6

For Each LDATA IN DATA

IF PASTECELL = "" THEN EXIT SUB

IF PASTECELL<> "" AND RANGE("Q" & CROW) = "" THEN RANGE("Q6") = PASTECELL

IF PASTECELL<> "" AND RANGE("Q" & CROW)<> "" THEN CROW = CROW + 1

NEXT LDATA


This any better?

_________________
LASW10
This message was edited by lasw10 on 2002-10-30 05:39
 
Upvote 0
Hi lasw,
Nearly
i think that this line:
If PASTECELL <> "" And Range("Q" & CROW) <> "" Then CROW = CROW + 1
is picking up the 1st entry in Q6 and does not go on to next row
Thanks for your help
Sue
 
Upvote 0
its a loop so in theory if the string isn't null and the value in Q & current row (which is variable) is not blank then it adds one to the row and loops to the next row in Q - when it hits a Q which is blank it should paste the contents of N25 into it.

Is this definitely not working?
 
Upvote 0
Hi lasw,
yes it does not work, it replaces string in Q6 instead of moving down to next row and writing into next cell down.,
I didnt notice before as i used the same input from N25, sorry.
Sue
 
Upvote 0
Sorry Sue my fault didn't notice it!!!

Sub test()

PASTECELL = Range("N25")

DATA = Range("Q6:Q100")
CROW = 6

For Each LDATA In DATA

If PASTECELL = "" Then Exit Sub

If PASTECELL <> "" And Range("Q" & CROW) = "" Then
Range("Q" & CROW) = PASTECELL
Exit Sub
End If

If PASTECELL <> "" And Range("Q" & CROW) <> "" Then CROW = CROW + 1

Next LDATA



End Sub
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

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