PC Review


Reply
Thread Tools Rate Thread

How to Check cell column A and add 1 to cell of column D by using Macro

 
 
tlee
Guest
Posts: n/a
 
      29th Jun 2009

Dear all,

Could anyone help how do I loop to check cells of column A if there is not
empty, then add 1 to cell of column D and stop until the cell of column A is
empty?

Thanks for your help.

tlee


 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      29th Jun 2009

for rw = 1 to range("A65500").End(xlUp).Row
if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
next

"tlee" <(E-Mail Removed)> wrote in message
news:#rBEgXJ#(E-Mail Removed)...
> Dear all,
>
> Could anyone help how do I loop to check cells of column A if there is not
> empty, then add 1 to cell of column D and stop until the cell of column A
> is empty?
>
> Thanks for your help.
>
> tlee
>
>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      29th Jun 2009

Hi Patrick,

Thanks for your message first.

But, it is not respond. Can help again?

tlee

> for rw = 1 to range("A65500").End(xlUp).Row
> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
> next
>
> "tlee" <(E-Mail Removed)> wrote in message
> news:#rBEgXJ#(E-Mail Removed)...
>> Dear all,
>>
>> Could anyone help how do I loop to check cells of column A if there is
>> not empty, then add 1 to cell of column D and stop until the cell of
>> column A is empty?
>>
>> Thanks for your help.
>>
>> tlee
>>
>>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      29th Jun 2009

Maybe this

Sub Marine()
Dim MyRange As Range
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & Lastrow)
For Each c In MyRange
If c.Value <> "" Then
c.Offset(, 3).Value = c.Offset(, 3).Value + 1
End If
Next
End Sub

Mike

"tlee" wrote:

> Dear all,
>
> Could anyone help how do I loop to check cells of column A if there is not
> empty, then add 1 to cell of column D and stop until the cell of column A is
> empty?
>
> Thanks for your help.
>
> tlee
>
>
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      29th Jun 2009

1.go to the development environment - press and hold ALT then press F11
2. from the menu click "INSERT" then "MODULE"
3. type
SUB DEMO
4. paste into the sub the code i gave to you
5. EITHER
(a) press F5
OR
(b) go back to the work sheet. select Tools / Macro /Macros , select
Demo from the list and click "Run"




"tlee" <(E-Mail Removed)> wrote in message
news:u$j743J%(E-Mail Removed)...
> Hi Patrick,
>
> Thanks for your message first.
>
> But, it is not respond. Can help again?
>
> tlee
>
>> for rw = 1 to range("A65500").End(xlUp).Row
>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>> next
>>
>> "tlee" <(E-Mail Removed)> wrote in message
>> news:#rBEgXJ#(E-Mail Removed)...
>>> Dear all,
>>>
>>> Could anyone help how do I loop to check cells of column A if there is
>>> not empty, then add 1 to cell of column D and stop until the cell of
>>> column A is empty?
>>>
>>> Thanks for your help.
>>>
>>> tlee
>>>
>>>


 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      29th Jun 2009

Hi Partick,

Thanks for you help again!!!

It is because it takes time for check the column A. As the result, I cannot
see the result immediately.
So, I changed End(xlup) to End(xldown).

Likes:
for rw = 1 to range("A65500").End(xldown).Row
if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
next

Then I can see the action promptly.

Thanks
tlee


> 1.go to the development environment - press and hold ALT then press F11
> 2. from the menu click "INSERT" then "MODULE"
> 3. type
> SUB DEMO
> 4. paste into the sub the code i gave to you
> 5. EITHER
> (a) press F5
> OR
> (b) go back to the work sheet. select Tools / Macro /Macros , select
> Demo from the list and click "Run"
>
>
>
>
> "tlee" <(E-Mail Removed)> wrote in message
> news:u$j743J%(E-Mail Removed)...
>> Hi Patrick,
>>
>> Thanks for your message first.
>>
>> But, it is not respond. Can help again?
>>
>> tlee
>>
>>> for rw = 1 to range("A65500").End(xlUp).Row
>>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>>> next
>>>
>>> "tlee" <(E-Mail Removed)> wrote in message
>>> news:#rBEgXJ#(E-Mail Removed)...
>>>> Dear all,
>>>>
>>>> Could anyone help how do I loop to check cells of column A if there is
>>>> not empty, then add 1 to cell of column D and stop until the cell of
>>>> column A is empty?
>>>>
>>>> Thanks for your help.
>>>>
>>>> tlee
>>>>
>>>>

>



 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      29th Jun 2009

Hi Mike,

Thanks for your message and help !!!

tlee


> Maybe this
>
> Sub Marine()
> Dim MyRange As Range
> Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
> Set MyRange = Range("A1:A" & Lastrow)
> For Each c In MyRange
> If c.Value <> "" Then
> c.Offset(, 3).Value = c.Offset(, 3).Value + 1
> End If
> Next
> End Sub
>
> Mike
>
> "tlee" wrote:
>
>> Dear all,
>>
>> Could anyone help how do I loop to check cells of column A if there is
>> not
>> empty, then add 1 to cell of column D and stop until the cell of column A
>> is
>> empty?
>>
>> Thanks for your help.
>>
>> tlee
>>
>>
>>



 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      29th Jun 2009

but xlDown stops at the first blank cell in A. I deliberately used xlUp to
cover all blanks

"tlee" <(E-Mail Removed)> wrote in message
news:u35uwxN#(E-Mail Removed)...
> Hi Partick,
>
> Thanks for you help again!!!
>
> It is because it takes time for check the column A. As the result, I
> cannot see the result immediately.
> So, I changed End(xlup) to End(xldown).
>
> Likes:
> for rw = 1 to range("A65500").End(xldown).Row
> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
> next
>
> Then I can see the action promptly.
>
> Thanks
> tlee
>
>
>> 1.go to the development environment - press and hold ALT then press F11
>> 2. from the menu click "INSERT" then "MODULE"
>> 3. type
>> SUB DEMO
>> 4. paste into the sub the code i gave to you
>> 5. EITHER
>> (a) press F5
>> OR
>> (b) go back to the work sheet. select Tools / Macro /Macros , select
>> Demo from the list and click "Run"
>>
>>
>>
>>
>> "tlee" <(E-Mail Removed)> wrote in message
>> news:u$j743J%(E-Mail Removed)...
>>> Hi Patrick,
>>>
>>> Thanks for your message first.
>>>
>>> But, it is not respond. Can help again?
>>>
>>> tlee
>>>
>>>> for rw = 1 to range("A65500").End(xlUp).Row
>>>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>>>> next
>>>>
>>>> "tlee" <(E-Mail Removed)> wrote in message
>>>> news:#rBEgXJ#(E-Mail Removed)...
>>>>> Dear all,
>>>>>
>>>>> Could anyone help how do I loop to check cells of column A if there is
>>>>> not empty, then add 1 to cell of column D and stop until the cell of
>>>>> column A is empty?
>>>>>
>>>>> Thanks for your help.
>>>>>
>>>>> tlee
>>>>>
>>>>>

>>

>
>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      30th Jun 2009
Hi Partick,

Thanks for your recommendation.

Besides, how do it check the cell of column A when it is blank, it will
delete the row at that cell?
I think as you said it is better to use xlUP.

tlee


> but xlDown stops at the first blank cell in A. I deliberately used xlUp to
> cover all blanks
>
> "tlee" <(E-Mail Removed)> wrote in message
> news:u35uwxN#(E-Mail Removed)...
>> Hi Partick,
>>
>> Thanks for you help again!!!
>>
>> It is because it takes time for check the column A. As the result, I
>> cannot see the result immediately.
>> So, I changed End(xlup) to End(xldown).
>>
>> Likes:
>> for rw = 1 to range("A65500").End(xldown).Row
>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>> next
>>
>> Then I can see the action promptly.
>>
>> Thanks
>> tlee
>>
>>
>>> 1.go to the development environment - press and hold ALT then press F11
>>> 2. from the menu click "INSERT" then "MODULE"
>>> 3. type
>>> SUB DEMO
>>> 4. paste into the sub the code i gave to you
>>> 5. EITHER
>>> (a) press F5
>>> OR
>>> (b) go back to the work sheet. select Tools / Macro /Macros , select
>>> Demo from the list and click "Run"
>>>
>>>
>>>
>>>
>>> "tlee" <(E-Mail Removed)> wrote in message
>>> news:u$j743J%(E-Mail Removed)...
>>>> Hi Patrick,
>>>>
>>>> Thanks for your message first.
>>>>
>>>> But, it is not respond. Can help again?
>>>>
>>>> tlee
>>>>
>>>>> for rw = 1 to range("A65500").End(xlUp).Row
>>>>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>>>>> next
>>>>>
>>>>> "tlee" <(E-Mail Removed)> wrote in message
>>>>> news:#rBEgXJ#(E-Mail Removed)...
>>>>>> Dear all,
>>>>>>
>>>>>> Could anyone help how do I loop to check cells of column A if there
>>>>>> is not empty, then add 1 to cell of column D and stop until the cell
>>>>>> of column A is empty?
>>>>>>
>>>>>> Thanks for your help.
>>>>>>
>>>>>> tlee
>>>>>>
>>>>>>
>>>

>>
>>


-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com
 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      30th Jun 2009

the object was to check all cells in column A and put 1 into D for any row
where there was nothing in A.

my code did that.

alternative method:-

dim nn as long
nn = range("A65000").End(xlUp).Row
WITH Range("D2" & nn )
.FormulaR1C1="=IF(RC1="""",1,"""")"
.Calculate
.Value = .Value
End With




"tlee" <(E-Mail Removed)> wrote in message
news:#T2OoqS#(E-Mail Removed)...
> Hi Partick,
>
> Thanks for your recommendation.
>
> Besides, how do it check the cell of column A when it is blank, it will
> delete the row at that cell?
> I think as you said it is better to use xlUP.
>
> tlee
>
>
>> but xlDown stops at the first blank cell in A. I deliberately used xlUp
>> to cover all blanks
>>
>> "tlee" <(E-Mail Removed)> wrote in message
>> news:u35uwxN#(E-Mail Removed)...
>>> Hi Partick,
>>>
>>> Thanks for you help again!!!
>>>
>>> It is because it takes time for check the column A. As the result, I
>>> cannot see the result immediately.
>>> So, I changed End(xlup) to End(xldown).
>>>
>>> Likes:
>>> for rw = 1 to range("A65500").End(xldown).Row
>>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>>> next
>>>
>>> Then I can see the action promptly.
>>>
>>> Thanks
>>> tlee
>>>
>>>
>>>> 1.go to the development environment - press and hold ALT then press F11
>>>> 2. from the menu click "INSERT" then "MODULE"
>>>> 3. type
>>>> SUB DEMO
>>>> 4. paste into the sub the code i gave to you
>>>> 5. EITHER
>>>> (a) press F5
>>>> OR
>>>> (b) go back to the work sheet. select Tools / Macro /Macros , select
>>>> Demo from the list and click "Run"
>>>>
>>>>
>>>>
>>>>
>>>> "tlee" <(E-Mail Removed)> wrote in message
>>>> news:u$j743J%(E-Mail Removed)...
>>>>> Hi Patrick,
>>>>>
>>>>> Thanks for your message first.
>>>>>
>>>>> But, it is not respond. Can help again?
>>>>>
>>>>> tlee
>>>>>
>>>>>> for rw = 1 to range("A65500").End(xlUp).Row
>>>>>> if cells(rw,1)="" then cells(rw,"D")= cells(rw,"D") + 1
>>>>>> next
>>>>>>
>>>>>> "tlee" <(E-Mail Removed)> wrote in message
>>>>>> news:#rBEgXJ#(E-Mail Removed)...
>>>>>>> Dear all,
>>>>>>>
>>>>>>> Could anyone help how do I loop to check cells of column A if there
>>>>>>> is not empty, then add 1 to cell of column D and stop until the cell
>>>>>>> of column A is empty?
>>>>>>>
>>>>>>> Thanks for your help.
>>>>>>>
>>>>>>> tlee
>>>>>>>
>>>>>>>
>>>>
>>>
>>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to split the contents in a single cell separated by "," intonext cell in that column anshu minocha Microsoft Excel Programming 3 21st Jan 2010 08:01 PM
Maddening Dilemma - Compare each cell within column a to each cell in column b and find unique matches pogster@gmail.com Microsoft Excel Worksheet Functions 65 16th Nov 2007 07:27 PM
Need the formula or macro. If i enter today date in the cell (Row 1,Column 2) and on tab out, the column 1 cell should be filled with "corresponding Day" of the date kakasay Microsoft Excel Misc 0 22nd Jan 2007 12:22 PM
Need Formula or macro. If i enter today date in the cell (Row 1,Column 2) and on tab out, the column 1 cell should be filled with "corresponding Day" of the date kakasay Microsoft Excel Misc 0 22nd Jan 2007 12:16 PM
check active cell column =?Utf-8?B?S2ltUi5IYW1tZWw=?= Microsoft Excel Programming 2 10th Aug 2005 09:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:46 PM.