Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Macro to delete certain cells

Hi Within my spreadsheet I have columns F and G populated with different text
eg.

F G
HVKHC UIGIUG
UGIUGGUI
OIHIH
IUGIUG 9YHIH

What I require is a macro that will clear cell G if the corresponding cell F
is not blank. So looking at the top row I want to keep HVKHC in column F but
clear UIGIUG in column G. Looking at rows 2 and 3 no action should be done.

It is important that column G is cleared and not fully deleted as I have
data past column G.

Any ideas?

Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Macro to delete certain cells



Sub ClearG()
lastrow = Cells(Rows.Count, "F").End(xlUp).Row
For r = 2 To lastrow
If Cells(r, "F") < "" Then Cells(r, "G") = ""
Next
End Sub

"Chris_t_2k5" wrote:

Hi Within my spreadsheet I have columns F and G populated with different text
eg.

F G
HVKHC UIGIUG
UGIUGGUI
OIHIH
IUGIUG 9YHIH

What I require is a macro that will clear cell G if the corresponding cell F
is not blank. So looking at the top row I want to keep HVKHC in column F but
clear UIGIUG in column G. Looking at rows 2 and 3 no action should be done.

It is important that column G is cleared and not fully deleted as I have
data past column G.

Any ideas?

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro to delete certain cells

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim rng As Range

iLastRow = Cells(Rows.Count, "F").End(xlUp).Row
For i = 1 To iLastRow
If Cells(i, "F").Value < "" Then
If rng Is Nothing Then
Set rng = Cells(i,"G")
Else
Set rng = Union(rng, Cells(i,"G"))
End If
End If
Next i

If Not rng Is Nothing Then rng.ClearContents

End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Chris_t_2k5" wrote in message
...
Hi Within my spreadsheet I have columns F and G populated with different

text
eg.

F G
HVKHC UIGIUG
UGIUGGUI
OIHIH
IUGIUG 9YHIH

What I require is a macro that will clear cell G if the corresponding cell

F
is not blank. So looking at the top row I want to keep HVKHC in column F

but
clear UIGIUG in column G. Looking at rows 2 and 3 no action should be

done.

It is important that column G is cleared and not fully deleted as I have
data past column G.

Any ideas?

Thanks in advance



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Empty Cells in a Macro fak119 Excel Discussion (Misc queries) 3 January 9th 07 04:58 PM
Macro to delete a group of CELLS Excel Discussion (Misc queries) 4 May 8th 06 04:29 PM
macro to select cells containing specific text and delete all cells but these JenIT Excel Programming 3 March 27th 06 10:07 PM
Macro to Delete blank cells GarToms Excel Worksheet Functions 1 January 26th 06 07:39 PM
macro to delete empty cells Tom Ogilvy Excel Programming 3 August 12th 03 08:06 PM


All times are GMT +1. The time now is 04:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"