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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
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?
 

Airwolf

Board Regular
Joined
Jul 24, 2002
Messages
123
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
 

sueandco

New Member
Joined
Oct 19, 2002
Messages
31
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
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123

ADVERTISEMENT

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
 

sueandco

New Member
Joined
Oct 19, 2002
Messages
31
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
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123

ADVERTISEMENT

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?
 

sueandco

New Member
Joined
Oct 19, 2002
Messages
31
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
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
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
 

Forum statistics

Threads
1,148,283
Messages
5,745,842
Members
423,981
Latest member
ph1l

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
Top