Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default UserForm past data

I have a series of cells on a worksheet which when clicked on open a
DialogBox. The DialogBox has ListBox which references another worksheet in
the same workbook, when I click OK it deposits the ListBox value into the
triggering cell. All of this works great, except, I also need to maintain
the font formatting (color) when it places the value in the triggering cell.
Is there any way to modify the code below to accomplish this?






Private Sub CommandButton1_Click()

'This UserForm is used to populate the Operator to Cover section of the
worksheet

On Error GoTo EndMacro

Friday_Routes_to_Cover.Hide
DoEvents

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 4).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 7).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng(1, 10).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng(1, 13).Value = ListBox1.List(ListBox1.ListIndex, 3)

rng(1, 6).Value = ListBox1.List(ListBox1.ListIndex, 13)
rng(1, 9).Value = ListBox1.List(ListBox1.ListIndex, 14)
rng(1, 12).Value = ListBox1.List(ListBox1.ListIndex, 15)
rng(1, 15).Value = ListBox1.List(ListBox1.ListIndex, 16)


Unload Friday_Routes_to_Cover

EndMacro:

Unload Friday_Routes_to_Cover

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UserForm past data

From just looking at your code I can't see why dumping values to cells
should change any formats (other than mixed formats if that's what you
have).

However if I'm missing something, trap the colorindex of the font in the
active cell (triggering cell?) and re-apply when done.

fntClrIdx = activecell.font.colorindex
'code
' when done
activecell.font.colorindex = fntClrIdx

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I have a series of cells on a worksheet which when clicked on open a
DialogBox. The DialogBox has ListBox which references another worksheet in
the same workbook, when I click OK it deposits the ListBox value into the
triggering cell. All of this works great, except, I also need to maintain
the font formatting (color) when it places the value in the triggering

cell.
Is there any way to modify the code below to accomplish this?






Private Sub CommandButton1_Click()

'This UserForm is used to populate the Operator to Cover section of the
worksheet

On Error GoTo EndMacro

Friday_Routes_to_Cover.Hide
DoEvents

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 4).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 7).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng(1, 10).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng(1, 13).Value = ListBox1.List(ListBox1.ListIndex, 3)

rng(1, 6).Value = ListBox1.List(ListBox1.ListIndex, 13)
rng(1, 9).Value = ListBox1.List(ListBox1.ListIndex, 14)
rng(1, 12).Value = ListBox1.List(ListBox1.ListIndex, 15)
rng(1, 15).Value = ListBox1.List(ListBox1.ListIndex, 16)


Unload Friday_Routes_to_Cover

EndMacro:

Unload Friday_Routes_to_Cover

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default UserForm past data

I am sorry I was not clear.

The data in the row source for the ListBox is contained on another
worksheet. That data's font has a color based upon certain variables. When
that data is deposited into the triggering cell, I need it to be the same
color as it was on the source worksheet.

"Peter T" <peter_t@discussions wrote in message
...
From just looking at your code I can't see why dumping values to cells
should change any formats (other than mixed formats if that's what you
have).

However if I'm missing something, trap the colorindex of the font in the
active cell (triggering cell?) and re-apply when done.

fntClrIdx = activecell.font.colorindex
'code
' when done
activecell.font.colorindex = fntClrIdx

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I have a series of cells on a worksheet which when clicked on open a
DialogBox. The DialogBox has ListBox which references another worksheet
in
the same workbook, when I click OK it deposits the ListBox value into the
triggering cell. All of this works great, except, I also need to maintain
the font formatting (color) when it places the value in the triggering

cell.
Is there any way to modify the code below to accomplish this?






Private Sub CommandButton1_Click()

'This UserForm is used to populate the Operator to Cover section of the
worksheet

On Error GoTo EndMacro

Friday_Routes_to_Cover.Hide
DoEvents

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 4).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 7).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng(1, 10).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng(1, 13).Value = ListBox1.List(ListBox1.ListIndex, 3)

rng(1, 6).Value = ListBox1.List(ListBox1.ListIndex, 13)
rng(1, 9).Value = ListBox1.List(ListBox1.ListIndex, 14)
rng(1, 12).Value = ListBox1.List(ListBox1.ListIndex, 15)
rng(1, 15).Value = ListBox1.List(ListBox1.ListIndex, 16)


Unload Friday_Routes_to_Cover

EndMacro:

Unload Friday_Routes_to_Cover

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UserForm past data

OK that's a bit clearer, but not much.

Following just a guess of what you want to achieve based on what you posted.
Looks like your rowsource has at least 17 columns; this should apply same
colour font to the various destination cells as applied in the respective
data cells. Like I said, it's only a guess, adapt as required.


Private Sub CommandButton1_Click()
Dim i As Long, nRow As Long, nLstIdx As Long
Dim rngList As Range
Dim aCols, aLstCols

aCols = Array(4, 7, 10, 13, 6, 9, 12, 15)
aLstCols = Array(0, 1, 2, 3, 13, 14, 15, 16)

Set rngList = Range(Me.ListBox1.RowSource)
nRow = ActiveCell.Row
nLstIdx = Me.ListBox1.ListIndex

If nRow Me.ListBox1.ListCount Or nLstIdx = -1 Then
MsgBox "activecell row out of range or no list row selected"
Exit Sub
End If

For i = 0 To UBound(aCols)
With Cells(nRow, aCols(i))
.Value = ListBox1.List(nLstIdx, aLstCols(i))
.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1)
End With
Next

End Sub

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
I am sorry I was not clear.

The data in the row source for the ListBox is contained on another
worksheet. That data's font has a color based upon certain variables. When
that data is deposited into the triggering cell, I need it to be the same
color as it was on the source worksheet.

"Peter T" <peter_t@discussions wrote in message
...
From just looking at your code I can't see why dumping values to cells
should change any formats (other than mixed formats if that's what you
have).

However if I'm missing something, trap the colorindex of the font in the
active cell (triggering cell?) and re-apply when done.

fntClrIdx = activecell.font.colorindex
'code
' when done
activecell.font.colorindex = fntClrIdx

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I have a series of cells on a worksheet which when clicked on open a
DialogBox. The DialogBox has ListBox which references another worksheet
in
the same workbook, when I click OK it deposits the ListBox value into

the
triggering cell. All of this works great, except, I also need to

maintain
the font formatting (color) when it places the value in the triggering

cell.
Is there any way to modify the code below to accomplish this?






Private Sub CommandButton1_Click()

'This UserForm is used to populate the Operator to Cover section of the
worksheet

On Error GoTo EndMacro

Friday_Routes_to_Cover.Hide
DoEvents

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 4).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 7).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng(1, 10).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng(1, 13).Value = ListBox1.List(ListBox1.ListIndex, 3)

rng(1, 6).Value = ListBox1.List(ListBox1.ListIndex, 13)
rng(1, 9).Value = ListBox1.List(ListBox1.ListIndex, 14)
rng(1, 12).Value = ListBox1.List(ListBox1.ListIndex, 15)
rng(1, 15).Value = ListBox1.List(ListBox1.ListIndex, 16)


Unload Friday_Routes_to_Cover

EndMacro:

Unload Friday_Routes_to_Cover

End Sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default UserForm past data

Thank you, but I get a Type Mismatch error on the following line:

..Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1)




"Peter T" <peter_t@discussions wrote in message
...
OK that's a bit clearer, but not much.

Following just a guess of what you want to achieve based on what you
posted.
Looks like your rowsource has at least 17 columns; this should apply same
colour font to the various destination cells as applied in the respective
data cells. Like I said, it's only a guess, adapt as required.


Private Sub CommandButton1_Click()
Dim i As Long, nRow As Long, nLstIdx As Long
Dim rngList As Range
Dim aCols, aLstCols

aCols = Array(4, 7, 10, 13, 6, 9, 12, 15)
aLstCols = Array(0, 1, 2, 3, 13, 14, 15, 16)

Set rngList = Range(Me.ListBox1.RowSource)
nRow = ActiveCell.Row
nLstIdx = Me.ListBox1.ListIndex

If nRow Me.ListBox1.ListCount Or nLstIdx = -1 Then
MsgBox "activecell row out of range or no list row selected"
Exit Sub
End If

For i = 0 To UBound(aCols)
With Cells(nRow, aCols(i))
.Value = ListBox1.List(nLstIdx, aLstCols(i))
.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1)
End With
Next

End Sub

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
I am sorry I was not clear.

The data in the row source for the ListBox is contained on another
worksheet. That data's font has a color based upon certain variables.
When
that data is deposited into the triggering cell, I need it to be the same
color as it was on the source worksheet.

"Peter T" <peter_t@discussions wrote in message
...
From just looking at your code I can't see why dumping values to cells
should change any formats (other than mixed formats if that's what you
have).

However if I'm missing something, trap the colorindex of the font in
the
active cell (triggering cell?) and re-apply when done.

fntClrIdx = activecell.font.colorindex
'code
' when done
activecell.font.colorindex = fntClrIdx

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I have a series of cells on a worksheet which when clicked on open a
DialogBox. The DialogBox has ListBox which references another
worksheet
in
the same workbook, when I click OK it deposits the ListBox value into

the
triggering cell. All of this works great, except, I also need to

maintain
the font formatting (color) when it places the value in the triggering
cell.
Is there any way to modify the code below to accomplish this?






Private Sub CommandButton1_Click()

'This UserForm is used to populate the Operator to Cover section of
the
worksheet

On Error GoTo EndMacro

Friday_Routes_to_Cover.Hide
DoEvents

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 4).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 7).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng(1, 10).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng(1, 13).Value = ListBox1.List(ListBox1.ListIndex, 3)

rng(1, 6).Value = ListBox1.List(ListBox1.ListIndex, 13)
rng(1, 9).Value = ListBox1.List(ListBox1.ListIndex, 14)
rng(1, 12).Value = ListBox1.List(ListBox1.ListIndex, 15)
rng(1, 15).Value = ListBox1.List(ListBox1.ListIndex, 16)


Unload Friday_Routes_to_Cover

EndMacro:

Unload Friday_Routes_to_Cover

End Sub









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UserForm past data

Somehow an important bit got lost in the posting, change

.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1)

to
..Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1).Font.ColorIndex

As written, font colorIndex of the row(nLstIdx + 1), column(aLstCols(i) + 1)
of the rowsource range is applied to the cell receiving the data.

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
Thank you, but I get a Type Mismatch error on the following line:

.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1)




"Peter T" <peter_t@discussions wrote in message
...
OK that's a bit clearer, but not much.

Following just a guess of what you want to achieve based on what you
posted.
Looks like your rowsource has at least 17 columns; this should apply

same
colour font to the various destination cells as applied in the

respective
data cells. Like I said, it's only a guess, adapt as required.


Private Sub CommandButton1_Click()
Dim i As Long, nRow As Long, nLstIdx As Long
Dim rngList As Range
Dim aCols, aLstCols

aCols = Array(4, 7, 10, 13, 6, 9, 12, 15)
aLstCols = Array(0, 1, 2, 3, 13, 14, 15, 16)

Set rngList = Range(Me.ListBox1.RowSource)
nRow = ActiveCell.Row
nLstIdx = Me.ListBox1.ListIndex

If nRow Me.ListBox1.ListCount Or nLstIdx = -1 Then
MsgBox "activecell row out of range or no list row selected"
Exit Sub
End If

For i = 0 To UBound(aCols)
With Cells(nRow, aCols(i))
.Value = ListBox1.List(nLstIdx, aLstCols(i))
.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1)
End With
Next

End Sub

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
I am sorry I was not clear.

The data in the row source for the ListBox is contained on another
worksheet. That data's font has a color based upon certain variables.
When
that data is deposited into the triggering cell, I need it to be the

same
color as it was on the source worksheet.

"Peter T" <peter_t@discussions wrote in message
...
From just looking at your code I can't see why dumping values to

cells
should change any formats (other than mixed formats if that's what

you
have).

However if I'm missing something, trap the colorindex of the font in
the
active cell (triggering cell?) and re-apply when done.

fntClrIdx = activecell.font.colorindex
'code
' when done
activecell.font.colorindex = fntClrIdx

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
I have a series of cells on a worksheet which when clicked on open a
DialogBox. The DialogBox has ListBox which references another
worksheet
in
the same workbook, when I click OK it deposits the ListBox value

into
the
triggering cell. All of this works great, except, I also need to

maintain
the font formatting (color) when it places the value in the

triggering
cell.
Is there any way to modify the code below to accomplish this?






Private Sub CommandButton1_Click()

'This UserForm is used to populate the Operator to Cover section of
the
worksheet

On Error GoTo EndMacro

Friday_Routes_to_Cover.Hide
DoEvents

Dim rng

Set rng = Cells(ActiveCell.Row, 1)

rng(1, 4).Value = ListBox1.List(ListBox1.ListIndex, 0)
rng(1, 7).Value = ListBox1.List(ListBox1.ListIndex, 1)
rng(1, 10).Value = ListBox1.List(ListBox1.ListIndex, 2)
rng(1, 13).Value = ListBox1.List(ListBox1.ListIndex, 3)

rng(1, 6).Value = ListBox1.List(ListBox1.ListIndex, 13)
rng(1, 9).Value = ListBox1.List(ListBox1.ListIndex, 14)
rng(1, 12).Value = ListBox1.List(ListBox1.ListIndex, 15)
rng(1, 15).Value = ListBox1.List(ListBox1.ListIndex, 16)


Unload Friday_Routes_to_Cover

EndMacro:

Unload Friday_Routes_to_Cover

End Sub









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default UserForm past data

Thank you very much, that was great.

I did have to remove the following code, because it would always tel me that "activecell row out of range or no list row selected"

If nRow Me.ListBox1.ListCount Or nLstIdx = -1 Then
MsgBox "activecell row out of range or no list row selected"
Exit Sub
End If

Is there any way to incorporate the remaining (green) code below? Those values are pasted in the row below.




Private Sub CommandButton1_Click()

'Friday_Route_Selection.Hide

Dim i As Long, nRow As Long, nLstIdx As Long
Dim rngList As Range
Dim aCols, aLstCols

aCols = Array(4, 7, 10, 13, 6, 9, 12, 15)
aLstCols = Array(0, 1, 2, 3, 13, 14, 15, 16)

Set rngList = Range(Me.ListBox1.RowSource)
nRow = ActiveCell.Row
nLstIdx = Me.ListBox1.ListIndex



For i = 0 To UBound(aCols)
With Cells(nRow, aCols(i))
.Value = ListBox1.List(nLstIdx, aLstCols(i))
.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) + 1).Font.ColorIndex
End With
Next

rng(2, 4).Value = ListBox1.List(ListBox1.ListIndex, 4)
rng(2, 5).Value = ListBox1.List(ListBox1.ListIndex, 5)
rng(2, 7).Value = ListBox1.List(ListBox1.ListIndex, 6)
rng(2, 8).Value = ListBox1.List(ListBox1.ListIndex, 7)
rng(2, 10).Value = ListBox1.List(ListBox1.ListIndex, 8)
rng(2, 11).Value = ListBox1.List(ListBox1.ListIndex, 9)
rng(2, 13).Value = ListBox1.List(ListBox1.ListIndex, 10)
rng(2, 14).Value = ListBox1.List(ListBox1.ListIndex, 11)

End Sub
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UserForm past data

I'm surprised the code works if you remove the initial test, actually two
tests

If nRow Me.ListBox1.ListCount then

If nRow, ie activecell row is more than the number of rows in your list the
rest of the code would fail (unless I've missed something).

If nLstIdx = -1 then
nLstIdx, ie .ListIndex = -1 indicates User has not selected a list row. The
list index is used to extract values so again it would fail, I would have
thought.

It might be worth splitting into two separate tests to determine which is
failing.


Looks like you have a second batch of data (greens ?) to dump in a similar
fashion in the row below the active row. Under the 1st loop make two new
arrays just like the first two with appropriate values,

aCols = Array(4, 5, 7, etc
aLstCols = Array(4, 5, 6, etc

and just below virtually the same loop

For i = 0 To UBound(aCols)
With Cells(nRow + 1, aCols(i))
.Value = ListBox1.List(nLstIdx, aLstCols(i))
.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) +
1).Font.ColorIndex
End

Notice the difference,
1st loop:With Cells(nRow, aCols(i))
2nd loop: With Cells(nRow, aCols(i))
ie, row below active row.

With the new code in place you should be able to remove your following code.

If you haven't already, it would be worth figuring how the code I've
suggested works, both to ensure it correctly does what you want and to make
simple modifications.

Regards,
Peter T

PS, In my newsreader your post appears with an attachment which was disabled


"Patrick C. Simonds" wrote in message
...
Thank you very much, that was great.

I did have to remove the following code, because it would always tel me that
"activecell row out of range or no list row selected"

If nRow Me.ListBox1.ListCount Or nLstIdx = -1 Then
MsgBox "activecell row out of range or no list row selected"
Exit Sub
End If

Is there any way to incorporate the remaining (green) code below? Those
values are pasted in the row below.




Private Sub CommandButton1_Click()

'Friday_Route_Selection.Hide

Dim i As Long, nRow As Long, nLstIdx As Long
Dim rngList As Range
Dim aCols, aLstCols

aCols = Array(4, 7, 10, 13, 6, 9, 12, 15)
aLstCols = Array(0, 1, 2, 3, 13, 14, 15, 16)

Set rngList = Range(Me.ListBox1.RowSource)
nRow = ActiveCell.Row
nLstIdx = Me.ListBox1.ListIndex



For i = 0 To UBound(aCols)
With Cells(nRow, aCols(i))
.Value = ListBox1.List(nLstIdx, aLstCols(i))
.Font.ColorIndex = rngList(nLstIdx + 1, aLstCols(i) +
1).Font.ColorIndex
End With
Next

rng(2, 4).Value = ListBox1.List(ListBox1.ListIndex, 4)
rng(2, 5).Value = ListBox1.List(ListBox1.ListIndex, 5)
rng(2, 7).Value = ListBox1.List(ListBox1.ListIndex, 6)
rng(2, 8).Value = ListBox1.List(ListBox1.ListIndex, 7)
rng(2, 10).Value = ListBox1.List(ListBox1.ListIndex, 8)
rng(2, 11).Value = ListBox1.List(ListBox1.ListIndex, 9)
rng(2, 13).Value = ListBox1.List(ListBox1.ListIndex, 10)
rng(2, 14).Value = ListBox1.List(ListBox1.ListIndex, 11)

End Sub


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
Past the total of select multi row data Qazi Ahmad Excel Discussion (Misc queries) 1 January 10th 07 02:57 PM
Search then copy and past data joecrabtree Excel Programming 3 December 8th 06 03:18 PM
How do you copy and past data from one spreadsheet to another? trainer07 Excel Discussion (Misc queries) 1 August 9th 06 07:21 PM
Count data based on past dates JimDandy Excel Worksheet Functions 7 June 28th 06 03:59 PM
Past directly into TextBox on UserForm DonB[_2_] Excel Programming 2 December 12th 03 02:01 AM


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