PC Review


Reply
Thread Tools Rate Thread

copying if value in cell from range of cells

 
 
thomsonpa
Guest
Posts: n/a
 
      11th Dec 2007
I am looking vor the visual basic code to perform the following action.
I have column "a" with data in every cell, columns "j, k and l 'may have
data in them.

If there is data in j, k or l I want to copy the data from "a" into another
worksheet in column "a", then the data in j, k or l in either b, c or d on
the other worksheet on the same row number as the information in column a.
Since column a has over 120 rows I am looking for a simple solution to this.
Any help in pointing me in the right direction would be helpful.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      11th Dec 2007
Sub movedata()

RowCount = 1
With Sheets("Sheet1")
Do While .Range("A" & RowCount) <> ""
If .Range("J" & RowCount) <> "" Or _
.Range("K" & RowCount) <> "" Or _
.Range("L" & RowCount) <> "" Then

ColA = .Range("A" & RowCount)
ColJ = .Range("J" & RowCount)
ColK = .Range("K" & RowCount)
ColL = .Range("L" & RowCount)

With Sheets("Sheet2")
.Range("A" & RowCount) = ColA
.Range("J" & RowCount) = ColJ
.Range("K" & RowCount) = ColK
.Range("L" & RowCount) = ColL

End With

End If
RowCount = RowCount + 1
Loop
End With

End Sub


"thomsonpa" wrote:

> I am looking vor the visual basic code to perform the following action.
> I have column "a" with data in every cell, columns "j, k and l 'may have
> data in them.
>
> If there is data in j, k or l I want to copy the data from "a" into another
> worksheet in column "a", then the data in j, k or l in either b, c or d on
> the other worksheet on the same row number as the information in column a.
> Since column a has over 120 rows I am looking for a simple solution to this.
> Any help in pointing me in the right direction would be helpful.

 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      11th Dec 2007
Try this:

Sub test()
hitcounter = 1
endA = Range("A" & Rows.Count).End(xlUp).Row
For Each acell In Range("A2:A" & endA)
If Not IsEmpty(Range("J" & acell.Row)) Or _
Not IsEmpty(Range("K" & acell.Row)) Or _
Not IsEmpty(Range("L" & acell.Row)) Then
hitcounter = hitcounter + 1
Worksheets("othersheet").Range("A" & hitcounter).Value =
acell.Value
Worksheets("othersheet").Range("B" & hitcounter).Value =
Range("J" & acell.Row).Value
Worksheets("othersheet").Range("C" & hitcounter).Value =
Range("K" & acell.Row).Value
Worksheets("othersheet").Range("D" & hitcounter).Value =
Range("L" & acell.Row).Value
End If
Next acell
End Sub

Regards,
Stefi

„thomsonpa” ezt *rta:

> I am looking vor the visual basic code to perform the following action.
> I have column "a" with data in every cell, columns "j, k and l 'may have
> data in them.
>
> If there is data in j, k or l I want to copy the data from "a" into another
> worksheet in column "a", then the data in j, k or l in either b, c or d on
> the other worksheet on the same row number as the information in column a.
> Since column a has over 120 rows I am looking for a simple solution to this.
> Any help in pointing me in the right direction would be helpful.

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      11th Dec 2007
Sub copyrangeif()'Execute from Source sheet
For i = 1 To Cells(Rows.Count, "a").End(xlUp).Row
With Sheets("yourdestinationsheetname")
lr = .Cells(Rows.Count, "a").End(xlUp).Row + 1
'MsgBox lr
If Len(Trim(Cells(i, "a"))) > 0 _
And Application.CountA(Range(Cells(i, "j"), Cells(i, "l"))) > 0 Then
'MsgBox i
Cells(i, "a").Copy .Cells(lr, "a")
Range(Cells(i, "j"), Cells(i, "l")).Copy .Cells(lr, "b")
End If
End With
Next i
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"thomsonpa" <(E-Mail Removed)> wrote in message
news:3EB66B36-4481-4E5C-8403-(E-Mail Removed)...
>I am looking vor the visual basic code to perform the following action.
> I have column "a" with data in every cell, columns "j, k and l 'may have
> data in them.
>
> If there is data in j, k or l I want to copy the data from "a" into
> another
> worksheet in column "a", then the data in j, k or l in either b, c or d on
> the other worksheet on the same row number as the information in column a.
> Since column a has over 120 rows I am looking for a simple solution to
> this.
> Any help in pointing me in the right direction would be helpful.


 
Reply With Quote
 
thomsonpa
Guest
Posts: n/a
 
      13th Dec 2007
Many thanks, works perfectly. What would I do if it wasnt for this community.

"Stefi" wrote:

> Try this:
>
> Sub test()
> hitcounter = 1
> endA = Range("A" & Rows.Count).End(xlUp).Row
> For Each acell In Range("A2:A" & endA)
> If Not IsEmpty(Range("J" & acell.Row)) Or _
> Not IsEmpty(Range("K" & acell.Row)) Or _
> Not IsEmpty(Range("L" & acell.Row)) Then
> hitcounter = hitcounter + 1
> Worksheets("othersheet").Range("A" & hitcounter).Value =
> acell.Value
> Worksheets("othersheet").Range("B" & hitcounter).Value =
> Range("J" & acell.Row).Value
> Worksheets("othersheet").Range("C" & hitcounter).Value =
> Range("K" & acell.Row).Value
> Worksheets("othersheet").Range("D" & hitcounter).Value =
> Range("L" & acell.Row).Value
> End If
> Next acell
> End Sub
>
> Regards,
> Stefi
>
> „thomsonpa” ezt *rta:
>
> > I am looking vor the visual basic code to perform the following action.
> > I have column "a" with data in every cell, columns "j, k and l 'may have
> > data in them.
> >
> > If there is data in j, k or l I want to copy the data from "a" into another
> > worksheet in column "a", then the data in j, k or l in either b, c or d on
> > the other worksheet on the same row number as the information in column a.
> > Since column a has over 120 rows I am looking for a simple solution to this.
> > Any help in pointing me in the right direction would be helpful.

 
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
copying a range of cells =?Utf-8?B?UEM=?= Microsoft Access VBA Modules 1 25th Sep 2007 05:14 AM
copying dynamic range based on cell outside of range xcelelder Microsoft Excel Programming 3 29th Sep 2005 05:08 PM
How do I skip blank cells when copying over a range of cells? =?Utf-8?B?dGF3ZWxscw==?= Microsoft Excel Misc 2 7th Jun 2005 09:36 PM
Copying a block of cells within a range of cells Mike Microsoft Excel Programming 6 21st Mar 2004 05:28 AM
Copying block (range of cells) based on a value of a specific cell-VBA Branimir Microsoft Excel Programming 1 15th Oct 2003 06:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:29 AM.