![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 10:28 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com