Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default Help with messy formula

The formula below works okay, but is a mixture of code which might cause some
problems for me down the road (and is probably not doing what I need it to do
very efficiently); I also ultimately need to setup something to copy the data
to the 'merge' worksheets which will be used by Word.

Yes, there is a reason the worksheets must be setup this way... if it helps,
the workbook (with fictional data) is on my Microsoft Office Live website:
http://suzleigh.com/MERGE.aspx (any comments/advice on how I can improve
anything in here would be GREATLY appreciated)

The formula below is linked to a command button

1. Copy cells containing data from PERSONNEL (columns A through I) to IHSF
DATA ENTRY (columns B through J)
2. Reduce the data in column I (SSN) to last 4
3. Return the focus to B2


Sub GetIHSFData()

Sheets("PERSONNEL DATA").Select
Range("A2:J500").Select
Selection.Copy
Sheets("IHSF DATA ENTRY").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

LastRow = Cells(Rows.Count, "I").End(xlUp).Row
For RowCount = 2 To LastRow
Data = Trim(Range("I" & RowCount))
If Len(Data) = 4 Then
Data = Trim(Right(Data, 4))
End If
If IsNumeric(Data) Then
Number = Val(Data)
End If
Range("I" & RowCount) = Number
Next RowCount

Range("B2").Select
End Sub

Thanks VERY much (also many thanks to everyone who got me to this point)

Suzanne

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Help with messy formula

Hi Suzanne

I would do it like that:
-------------------------------------------------
Sub GetIHSFData()

Sheets("PERSONNEL DATA").Range("A2:J500").Copy

With Sheets("IHSF DATA ENTRY")
.Range("B2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

For RowCount = 2 To .Cells(.Rows.Count, "I").End(xlUp).Row
Data_i = Right(Trim(.Range("I" & RowCount).Value), 4)
If IsNumeric(Data_i) Then
Number_I = Val(Data_i)
End If
.Range("I" & RowCount) = Number_I
Next RowCount

.Select
.Range("B2").Select

End With

End Sub
-----------------------------------------------------------------

I would not use Data and Number as variablenames, they may be used by
VBA.

I deleted the selecting of the cells, because it's unnecessary.

hope thats what you wanted

Carlo




On Dec 10, 2:27 pm, Suzanne wrote:
The formula below works okay, but is a mixture of code which might cause some
problems for me down the road (and is probably not doing what I need it to do
very efficiently); I also ultimately need to setup something to copy the data
to the 'merge' worksheets which will be used by Word.

Yes, there is a reason the worksheets must be setup this way... if it helps,
the workbook (with fictional data) is on my Microsoft Office Live website: http://suzleigh.com/MERGE.aspx (any comments/advice on how I can improve
anything in here would be GREATLY appreciated)

The formula below is linked to a command button

1. Copy cells containing data from PERSONNEL (columns A through I) to IHSF
DATA ENTRY (columns B through J)
2. Reduce the data in column I (SSN) to last 4
3. Return the focus to B2

Sub GetIHSFData()

Sheets("PERSONNEL DATA").Select
Range("A2:J500").Select
Selection.Copy
Sheets("IHSF DATA ENTRY").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

LastRow = Cells(Rows.Count, "I").End(xlUp).Row
For RowCount = 2 To LastRow
Data = Trim(Range("I" & RowCount))
If Len(Data) = 4 Then
Data = Trim(Right(Data, 4))
End If
If IsNumeric(Data) Then
Number = Val(Data)
End If
Range("I" & RowCount) = Number
Next RowCount

Range("B2").Select
End Sub

Thanks VERY much (also many thanks to everyone who got me to this point)

Suzanne


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
Messy Formula needs clean up help! Danny Boy Excel Worksheet Functions 7 March 19th 10 03:24 PM
VBA not working - Messy. NPell Excel Worksheet Functions 1 February 9th 09 02:46 PM
Messy Users Dkso Excel Programming 1 May 15th 06 05:59 PM
Messy tab characters Gargoyl Excel Discussion (Misc queries) 2 April 19th 06 11:09 PM
Messy Text to Columns sweeneysmsm Excel Discussion (Misc queries) 3 November 8th 05 01:08 AM


All times are GMT +1. The time now is 06:02 PM.

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"