Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Offset problem

As you can tell I use the code to place the contents of a Listbox into the
active cell and a cell 27 cells to the right. If I select a range of cells
(say A1 - E1) the ListBox content is placed in all selected cells but only
once in the cell 27 to the right of the first cell selected. I want a value
placed in the 27th cell from each of the selected cells.



Private Sub OK_Click()

ThisWorkbook.Activate

On Error GoTo Sub1

Selection = ListBox1.List(ListBox1.ListIndex, 0)
ActiveCell(1, 27).Value = ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Offset problem

Patrick:

You need to get the rows of the range that is currently selected:

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1

and the column

lColumn = selection.column + 26

and then you can use

range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value
= ListBox1.List(ListBox1.ListIndex, 4)


Private Sub OK_Click()
Dim lRowStart As Long, lRowEnd As Long, lColumn As Long

ThisWorkbook.Activate

On Error GoTo Sub1

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1
lColumn = selection.column + 26

Selection = ListBox1.List(ListBox1.ListIndex, 0)
Range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value _
= ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Patrick Simonds" wrote:

As you can tell I use the code to place the contents of a Listbox into the
active cell and a cell 27 cells to the right. If I select a range of cells
(say A1 - E1) the ListBox content is placed in all selected cells but only
once in the cell 27 to the right of the first cell selected. I want a value
placed in the 27th cell from each of the selected cells.



Private Sub OK_Click()

ThisWorkbook.Activate

On Error GoTo Sub1

Selection = ListBox1.List(ListBox1.ListIndex, 0)
ActiveCell(1, 27).Value = ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Offset problem

This does not seem to put the value in all the offset cells, only the first
one.

"Martin Fishlock" wrote in message
...
Patrick:

You need to get the rows of the range that is currently selected:

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1

and the column

lColumn = selection.column + 26

and then you can use

range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value
= ListBox1.List(ListBox1.ListIndex, 4)


Private Sub OK_Click()
Dim lRowStart As Long, lRowEnd As Long, lColumn As Long

ThisWorkbook.Activate

On Error GoTo Sub1

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1
lColumn = selection.column + 26

Selection = ListBox1.List(ListBox1.ListIndex, 0)
Range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value _
= ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Patrick Simonds" wrote:

As you can tell I use the code to place the contents of a Listbox into
the
active cell and a cell 27 cells to the right. If I select a range of
cells
(say A1 - E1) the ListBox content is placed in all selected cells but
only
once in the cell 27 to the right of the first cell selected. I want a
value
placed in the 27th cell from each of the selected cells.



Private Sub OK_Click()

ThisWorkbook.Activate

On Error GoTo Sub1

Selection = ListBox1.List(ListBox1.ListIndex, 0)
ActiveCell(1, 27).Value = ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Offset problem

Patrick,

I just tried it again and it worked for me fine.

Did you clear the old data and select the area?

Try remarking the on error to see if you have an error.

Otherwise post your code and I will have a look again.
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Patrick Simonds" wrote:

This does not seem to put the value in all the offset cells, only the first
one.

"Martin Fishlock" wrote in message
...
Patrick:

You need to get the rows of the range that is currently selected:

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1

and the column

lColumn = selection.column + 26

and then you can use

range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value
= ListBox1.List(ListBox1.ListIndex, 4)


Private Sub OK_Click()
Dim lRowStart As Long, lRowEnd As Long, lColumn As Long

ThisWorkbook.Activate

On Error GoTo Sub1

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1
lColumn = selection.column + 26

Selection = ListBox1.List(ListBox1.ListIndex, 0)
Range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value _
= ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Patrick Simonds" wrote:

As you can tell I use the code to place the contents of a Listbox into
the
active cell and a cell 27 cells to the right. If I select a range of
cells
(say A1 - E1) the ListBox content is placed in all selected cells but
only
once in the cell 27 to the right of the first cell selected. I want a
value
placed in the 27th cell from each of the selected cells.



Private Sub OK_Click()

ThisWorkbook.Activate

On Error GoTo Sub1

Selection = ListBox1.List(ListBox1.ListIndex, 0)
ActiveCell(1, 27).Value = ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Offset problem

Here is the code, pretty much as you presented it. I then select cells A1
through A3, when the Dialog box comes up I select a name from the Listbox.
For this example the name I select is Jane. Jane's name is placed in cells
A1 through A3. Now the other piece of information which should display is
Jane's status (PTO) and I want it displayed in the 27th cell over from each
of the cells (A1 through A3, which would be AA1 through AC1). What I get is
PTO in cell AA1 only. Hope that make sense.


Private Sub OK_Click()

Dim lRowStart As Long, lRowEnd As Long, lColumn As Long

lRowStart = Selection.Row
lRowEnd = lRowStart + Selection.Rows.Count - 1

lColumn = Selection.Column + 26

Range(Cells(lRowStart, lColumn), Cells(lRowEnd, lColumn)).Value =
ListBox1.List(ListBox1.ListIndex, 4)

ThisWorkbook.Activate

On Error GoTo Sub1

lRowStart = Selection.Row
lRowEnd = lRowStart + Selection.Rows.Count - 1
lColumn = Selection.Column + 26

Selection = ListBox1.List(ListBox1.ListIndex, 0)
Range(Cells(lRowStart, lColumn), Cells(lRowEnd, lColumn)).Value _
= ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0


Sub1:

Unload EmployeeList

End Sub





"Martin Fishlock" wrote in message
...
Patrick,

I just tried it again and it worked for me fine.

Did you clear the old data and select the area?

Try remarking the on error to see if you have an error.

Otherwise post your code and I will have a look again.
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Patrick Simonds" wrote:

This does not seem to put the value in all the offset cells, only the
first
one.

"Martin Fishlock" wrote in message
...
Patrick:

You need to get the rows of the range that is currently selected:

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1

and the column

lColumn = selection.column + 26

and then you can use

range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value
= ListBox1.List(ListBox1.ListIndex, 4)


Private Sub OK_Click()
Dim lRowStart As Long, lRowEnd As Long, lColumn As Long

ThisWorkbook.Activate

On Error GoTo Sub1

lRowStart = Selection.row
lRowEnd = lRowStart + selection.rows.count - 1
lColumn = selection.column + 26

Selection = ListBox1.List(ListBox1.ListIndex, 0)
Range(cells(lRowStart,lColumn), cells(lRowEnd,lColumn)).Value _
= ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Patrick Simonds" wrote:

As you can tell I use the code to place the contents of a Listbox into
the
active cell and a cell 27 cells to the right. If I select a range of
cells
(say A1 - E1) the ListBox content is placed in all selected cells but
only
once in the cell 27 to the right of the first cell selected. I want a
value
placed in the 27th cell from each of the selected cells.



Private Sub OK_Click()

ThisWorkbook.Activate

On Error GoTo Sub1

Selection = ListBox1.List(ListBox1.ListIndex, 0)
ActiveCell(1, 27).Value = ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

End Sub










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Offset problem

Selection.value = ListBox1.List(ListBox1.ListIndex, 0)
Selection.offset(0, 26).Value = ListBox1.List(ListBox1.ListIndex, 4)

--
Regards,
Luc.

"Festina Lente"


"Patrick Simonds" wrote:

As you can tell I use the code to place the contents of a Listbox into the
active cell and a cell 27 cells to the right. If I select a range of cells
(say A1 - E1) the ListBox content is placed in all selected cells but only
once in the cell 27 to the right of the first cell selected. I want a value
placed in the 27th cell from each of the selected cells.



Private Sub OK_Click()

ThisWorkbook.Activate

On Error GoTo Sub1

Selection = ListBox1.List(ListBox1.ListIndex, 0)
ActiveCell(1, 27).Value = ListBox1.List(ListBox1.ListIndex, 4)
ListBox1.ListIndex = 0

Sub1:

Unload EmployeeList

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
Offset VBA Problem jlclyde Excel Discussion (Misc queries) 3 September 18th 07 04:00 PM
Problem with an offset floep[_8_] Excel Programming 3 July 28th 06 03:40 PM
Offset Problem morrida3 New Users to Excel 1 September 16th 05 08:02 PM
Help with OFFSET Problem Please Paul Black[_2_] Excel Programming 5 February 26th 05 05:18 PM
OFFSET problem Sheela Excel Programming 0 December 26th 03 05:03 AM


All times are GMT +1. The time now is 02:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"