ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clear Contents (https://www.excelbanter.com/excel-programming/399374-clear-contents.html)

Steved

Clear Contents
 
Hello from Steved

Below is my attempt to clear contents from Colunmn J:J

my issue is that it clears the column first before combining the Col I and
Col J contents What is required please to change this Thankyou

Sub Trythis()
Dim lastcell As Long
Dim i As Long
lastcell = Cells(Rows.Count, "I").End(xlUp).Row
For i = 1 To lastcell
'combine Column I and J
Range("I" & i).Value = Range("I" & i).Value & " " & _
Range("I" & i).Offset(0, 1).Value
'clear column J value
Columns("J:J").Select
Selection.ClearContents
Next
End Sub



JLGWhiz

Clear Contents
 
You have your Next in the wrong place. Put it before the Columns("J").Select

"Steved" wrote:

Hello from Steved

Below is my attempt to clear contents from Colunmns(" J:J")
my issue is that it clears the column first before combining the Col I and
Col J contents What is required please to change this Thankyou

Sub Trythis()
Dim lastcell As Long
Dim i As Long
lastcell = Cells(Rows.Count, "I").End(xlUp).Row
For i = 1 To lastcell
'combine Column I and J
Range("I" & i).Value = Range("I" & i).Value & " " & _
Range("I" & i).Offset(0, 1).Value
'clear column J value
Columns("J:J").Select
Selection.ClearContents
Next
End Sub



FSt1

Clear Contents
 
hi
you are clearing the entire column J before the loop finishes. don't do that.
change....
Columns("J:J").Select
Selection.ClearContents
to....
Range("I" & i).Offset(0, 1).ClearContents

this way the contents of column will be cleared as the loop runs, not all at
once.

regards
FSt1

"Steved" wrote:

Hello from Steved

Below is my attempt to clear contents from Colunmn J:J

my issue is that it clears the column first before combining the Col I and
Col J contents What is required please to change this Thankyou

Sub Trythis()
Dim lastcell As Long
Dim i As Long
lastcell = Cells(Rows.Count, "I").End(xlUp).Row
For i = 1 To lastcell
'combine Column I and J
Range("I" & i).Value = Range("I" & i).Value & " " & _
Range("I" & i).Offset(0, 1).Value
'clear column J value
Columns("J:J").Select
Selection.ClearContents
Next
End Sub



Steved

Clear Contents
 
Thankyou.

"JLGWhiz" wrote:

You have your Next in the wrong place. Put it before the Columns("J").Select

"Steved" wrote:

Hello from Steved

Below is my attempt to clear contents from Colunmns(" J:J")
my issue is that it clears the column first before combining the Col I and
Col J contents What is required please to change this Thankyou

Sub Trythis()
Dim lastcell As Long
Dim i As Long
lastcell = Cells(Rows.Count, "I").End(xlUp).Row
For i = 1 To lastcell
'combine Column I and J
Range("I" & i).Value = Range("I" & i).Value & " " & _
Range("I" & i).Offset(0, 1).Value
'clear column J value
Columns("J:J").Select
Selection.ClearContents
Next
End Sub



Steved

Clear Contents
 
Thankyou.

"FSt1" wrote:

hi
you are clearing the entire column J before the loop finishes. don't do that.
change....
Columns("J:J").Select
Selection.ClearContents
to....
Range("I" & i).Offset(0, 1).ClearContents

this way the contents of column will be cleared as the loop runs, not all at
once.

regards
FSt1

"Steved" wrote:

Hello from Steved

Below is my attempt to clear contents from Colunmn J:J

my issue is that it clears the column first before combining the Col I and
Col J contents What is required please to change this Thankyou

Sub Trythis()
Dim lastcell As Long
Dim i As Long
lastcell = Cells(Rows.Count, "I").End(xlUp).Row
For i = 1 To lastcell
'combine Column I and J
Range("I" & i).Value = Range("I" & i).Value & " " & _
Range("I" & i).Offset(0, 1).Value
'clear column J value
Columns("J:J").Select
Selection.ClearContents
Next
End Sub




All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com