Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Macro VBA code to copy content from one worksheet to another

Hello. I have various worksheets in a workbook, each with 100 listed items
(B is description, C is price, D is availability - B1:B100, C1:C100,
D1:D100). I would to add checkboxes along A (A1:A100) where I can check, and
each time I check an item, that whole item with the various colums move to
another worksheet - lets call that worksheet SelectedCart (when I deselect an
item, it will disappear from SelectedCart). Also, I would each item added to
SelectedCart to be highlighted in different color (not sure if I should just
use Coditional Formatting).

I have a code that adds checkboxes and upon checking it adds date, but I am
not sure how I can do what I need (as listed above). Here is the code I have:

=================

Sub Process_CheckBox(pObject)

Dim LRow As Integer
Dim LRange As String

'Find row that checkbox resides in
LRow = pObject.TopLeftCell.Row
LRange = "B" & CStr(LRow)

'Change date in column B, if checkbox is checked
If pObject.Value = True Then
ActiveSheet.Range(LRange).Value = Date

'Clear date in column B, if checkbox is unchecked
Else
ActiveSheet.Range(LRange).Value = Null
End If

End Sub



Private Sub CheckBox1_Click()
Process_CheckBox CheckBox1
End Sub

Private Sub CheckBox2_Click()
Process_CheckBox CheckBox2
End Sub

Private Sub CheckBox3_Click()
Process_CheckBox CheckBox3
End Sub

Private Sub CheckBox4_Click()
Process_CheckBox CheckBox4
End Sub

Private Sub CheckBox5_Click()
Process_CheckBox CheckBox5
End Sub

Private Sub CheckBox6_Click()
Process_CheckBox CheckBox6
End Sub

Private Sub CheckBox7_Click()
Process_CheckBox CheckBox7
End Sub

=================

Any ideas where I can begin looking to do what I need? Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Macro VBA code to copy content from one worksheet to another

Here is one simple way

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "A:A" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "" Then
.Offset(0, 1).Resize(, 3).Copy _
Worksheets("Sheet2").Range("A" & .Row)
Worksheets("Sheet2").Rows(.Row).Interior.ColorInde x = 36
.Value = "a"
.Font.Name = "Marlett"
Else
Worksheets("Sheet2").Rows(.Row).ClearContents
Worksheets("Sheet2").Rows(.Row).Interior.ColorInde x =
xlColorIndexNone
.Value = ""
End If
.Offset(0, 1).Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Xocial" wrote in message
...
Hello. I have various worksheets in a workbook, each with 100 listed
items
(B is description, C is price, D is availability - B1:B100, C1:C100,
D1:D100). I would to add checkboxes along A (A1:A100) where I can check,
and
each time I check an item, that whole item with the various colums move to
another worksheet - lets call that worksheet SelectedCart (when I deselect
an
item, it will disappear from SelectedCart). Also, I would each item added
to
SelectedCart to be highlighted in different color (not sure if I should
just
use Coditional Formatting).

I have a code that adds checkboxes and upon checking it adds date, but I
am
not sure how I can do what I need (as listed above). Here is the code I
have:

=================

Sub Process_CheckBox(pObject)

Dim LRow As Integer
Dim LRange As String

'Find row that checkbox resides in
LRow = pObject.TopLeftCell.Row
LRange = "B" & CStr(LRow)

'Change date in column B, if checkbox is checked
If pObject.Value = True Then
ActiveSheet.Range(LRange).Value = Date

'Clear date in column B, if checkbox is unchecked
Else
ActiveSheet.Range(LRange).Value = Null
End If

End Sub



Private Sub CheckBox1_Click()
Process_CheckBox CheckBox1
End Sub

Private Sub CheckBox2_Click()
Process_CheckBox CheckBox2
End Sub

Private Sub CheckBox3_Click()
Process_CheckBox CheckBox3
End Sub

Private Sub CheckBox4_Click()
Process_CheckBox CheckBox4
End Sub

Private Sub CheckBox5_Click()
Process_CheckBox CheckBox5
End Sub

Private Sub CheckBox6_Click()
Process_CheckBox CheckBox6
End Sub

Private Sub CheckBox7_Click()
Process_CheckBox CheckBox7
End Sub

=================

Any ideas where I can begin looking to do what I need? Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Macro VBA code to copy content from one worksheet to another

Hello,
Does this code replaces or is in addition to the code I posted? Do I put
the module in the first worksheet or all the worksheets i have? I have 5 or
6 worksheets with inventory, then check the ones i want from each worksheet
that transfer over to the last worksheet which I called SelectedCart.

Thank you!

"Bob Phillips" wrote:

Here is one simple way

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "A:A" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "" Then
.Offset(0, 1).Resize(, 3).Copy _
Worksheets("Sheet2").Range("A" & .Row)
Worksheets("Sheet2").Rows(.Row).Interior.ColorInde x = 36
.Value = "a"
.Font.Name = "Marlett"
Else
Worksheets("Sheet2").Rows(.Row).ClearContents
Worksheets("Sheet2").Rows(.Row).Interior.ColorInde x =
xlColorIndexNone
.Value = ""
End If
.Offset(0, 1).Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Xocial" wrote in message
...
Hello. I have various worksheets in a workbook, each with 100 listed
items
(B is description, C is price, D is availability - B1:B100, C1:C100,
D1:D100). I would to add checkboxes along A (A1:A100) where I can check,
and
each time I check an item, that whole item with the various colums move to
another worksheet - lets call that worksheet SelectedCart (when I deselect
an
item, it will disappear from SelectedCart). Also, I would each item added
to
SelectedCart to be highlighted in different color (not sure if I should
just
use Coditional Formatting).

I have a code that adds checkboxes and upon checking it adds date, but I
am
not sure how I can do what I need (as listed above). Here is the code I
have:

=================

Sub Process_CheckBox(pObject)

Dim LRow As Integer
Dim LRange As String

'Find row that checkbox resides in
LRow = pObject.TopLeftCell.Row
LRange = "B" & CStr(LRow)

'Change date in column B, if checkbox is checked
If pObject.Value = True Then
ActiveSheet.Range(LRange).Value = Date

'Clear date in column B, if checkbox is unchecked
Else
ActiveSheet.Range(LRange).Value = Null
End If

End Sub



Private Sub CheckBox1_Click()
Process_CheckBox CheckBox1
End Sub

Private Sub CheckBox2_Click()
Process_CheckBox CheckBox2
End Sub

Private Sub CheckBox3_Click()
Process_CheckBox CheckBox3
End Sub

Private Sub CheckBox4_Click()
Process_CheckBox CheckBox4
End Sub

Private Sub CheckBox5_Click()
Process_CheckBox CheckBox5
End Sub

Private Sub CheckBox6_Click()
Process_CheckBox CheckBox6
End Sub

Private Sub CheckBox7_Click()
Process_CheckBox CheckBox7
End Sub

=================

Any ideas where I can begin looking to do what I need? Thank you.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Macro VBA code to copy content from one worksheet to another

That code is intended for just the one sheet, and instead of yours.

If you are trying to off-load many sheets onto one, should then just go to
the end of what is there. If so, how will we identify where it is on a
de-select?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Xocial" wrote in message
...
Hello,
Does this code replaces or is in addition to the code I posted? Do I put
the module in the first worksheet or all the worksheets i have? I have 5
or
6 worksheets with inventory, then check the ones i want from each
worksheet
that transfer over to the last worksheet which I called SelectedCart.

Thank you!

"Bob Phillips" wrote:

Here is one simple way

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "A:A" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "" Then
.Offset(0, 1).Resize(, 3).Copy _
Worksheets("Sheet2").Range("A" & .Row)
Worksheets("Sheet2").Rows(.Row).Interior.ColorInde x = 36
.Value = "a"
.Font.Name = "Marlett"
Else
Worksheets("Sheet2").Rows(.Row).ClearContents
Worksheets("Sheet2").Rows(.Row).Interior.ColorInde x =
xlColorIndexNone
.Value = ""
End If
.Offset(0, 1).Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Xocial" wrote in message
...
Hello. I have various worksheets in a workbook, each with 100 listed
items
(B is description, C is price, D is availability - B1:B100, C1:C100,
D1:D100). I would to add checkboxes along A (A1:A100) where I can
check,
and
each time I check an item, that whole item with the various colums move
to
another worksheet - lets call that worksheet SelectedCart (when I
deselect
an
item, it will disappear from SelectedCart). Also, I would each item
added
to
SelectedCart to be highlighted in different color (not sure if I should
just
use Coditional Formatting).

I have a code that adds checkboxes and upon checking it adds date, but
I
am
not sure how I can do what I need (as listed above). Here is the code
I
have:

=================

Sub Process_CheckBox(pObject)

Dim LRow As Integer
Dim LRange As String

'Find row that checkbox resides in
LRow = pObject.TopLeftCell.Row
LRange = "B" & CStr(LRow)

'Change date in column B, if checkbox is checked
If pObject.Value = True Then
ActiveSheet.Range(LRange).Value = Date

'Clear date in column B, if checkbox is unchecked
Else
ActiveSheet.Range(LRange).Value = Null
End If

End Sub



Private Sub CheckBox1_Click()
Process_CheckBox CheckBox1
End Sub

Private Sub CheckBox2_Click()
Process_CheckBox CheckBox2
End Sub

Private Sub CheckBox3_Click()
Process_CheckBox CheckBox3
End Sub

Private Sub CheckBox4_Click()
Process_CheckBox CheckBox4
End Sub

Private Sub CheckBox5_Click()
Process_CheckBox CheckBox5
End Sub

Private Sub CheckBox6_Click()
Process_CheckBox CheckBox6
End Sub

Private Sub CheckBox7_Click()
Process_CheckBox CheckBox7
End Sub

=================

Any ideas where I can begin looking to do what I need? Thank you.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Macro VBA code to copy content from one worksheet to another

Hello,
I tried your code in a blank workbook and nothing happened. I think I am
doing something wrong as I am not very seasoned in VBA or using it in Excel.

In essence, here is the layout of what I am trying to do (assuming it is
possible).

WorkSheet 1: Summary Page I created (done).
Worksheet 2: Inventory Type 1 that has 100 items (but may up a lot more)
Worksheet 3: Inventory Type 2 that has 100 items (but may up a lot more)
Worksheet 4: Inventory Type 3 that has 100 items (but may up a lot more)
Worksheet 5: Inventory Type 4 that has 100 items (but may up a lot more)
Worksheet 6: Inventory Type 5 that has 100 items (but may up a lot more)
Worksheet 7: Inventory Type 6 that has 100 items (but may up a lot more)
Worksheet 8: Inventory Type 7 that has 100 items (but may up a lot more)
Worksheet 9: This is the SelectedCart that will have the copied items that I
will check from worksheet2 - worksheet8.

The worksheets that have the inventory have various columns listed in B1:D1,
and go on from there, B2:D2, B3:D3, et cetera.

I would like the checked items in SelectedCart to have rotating colors (that
I will select). Is this possible to do in Excel?

Also, if I need to add or delete a worksheet, what part of the code do I
need to amend?

Thank you.


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
copy row content from one worksheet to another, if a condition met Lorilenore Excel Worksheet Functions 2 May 24th 08 08:36 PM
How do I copy a cell (content AND format) from one worksheet to a. Excel Format Copy Excel Worksheet Functions 1 February 9th 05 10:34 PM
Taking content from worksheet,loc it in another, and if exists. copy it to a third... grntdav Excel Programming 0 July 7th 04 02:25 PM
Copy Sheets minus Worksheet Change Event code & Macro Buttons Bob[_36_] Excel Programming 0 October 8th 03 01:17 AM
Record Worksheet Content as Macro and Execute from another Worksheet David McRitchie[_2_] Excel Programming 2 July 23rd 03 09:43 AM


All times are GMT +1. The time now is 04:45 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"