Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default How to make this code smaller

Hi,

I've got this which works fine.

Set sh1 = ActiveWorkbook.Sheets("Data")
Set sh2 = ActiveWorkbook.Sheets("UK")

'H1
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next
'H2
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H2" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next
'H3
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H3" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next


But as I'm looking at the same data in Sh1. Can this be made shorter by some
sort of Or here If c.Value = "H1" Then

Something like if c.Value = "H1","H2","H3" then?

Thanks
Carl
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default How to make this code smaller

If c.Value = "H1" Or c.Value = "H2" Or c.Value = "H3" Then

Regards,
Stefi

€˛Carlos€¯ ezt Ć*rta:

Hi,

I've got this which works fine.

Set sh1 = ActiveWorkbook.Sheets("Data")
Set sh2 = ActiveWorkbook.Sheets("UK")

'H1
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next
'H2
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H2" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next
'H3
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H3" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next


But as I'm looking at the same data in Sh1. Can this be made shorter by some
sort of Or here If c.Value = "H1" Then

Something like if c.Value = "H1","H2","H3" then?

Thanks
Carl

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default How to make this code smaller

Sub cutdatatoothersheet()
Set ds = Sheets("sheet1")
Set ss = Sheets("sheet6")
With ds
For i = 1 To ss.Cells(Rows.Count, 1).End(xlUp).Row
dlr = .Cells(Rows.Count, 1).End(xlUp).Row + 1
If UCase(ss.Cells(i, 1)) = "H1" Or _
UCase(ss.Cells(i, 1)) = "H2" Or _
UCase(ss.Cells(i, 1)) = "H3" Then
ss.Rows(i).Cut .Cells(dlr, 1)
ss.Rows(i).Delete
End If
Next i
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Stefi" wrote in message
...
If c.Value = "H1" Or c.Value = "H2" Or c.Value = "H3" Then

Regards,
Stefi

€˛Carlos€¯ ezt Ć*rta:

Hi,

I've got this which works fine.

Set sh1 = ActiveWorkbook.Sheets("Data")
Set sh2 = ActiveWorkbook.Sheets("UK")

'H1
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next
'H2
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H2" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next
'H3
For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H3" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut
Sheets("UK").Select
Rows(lr1 + 1).Select
ActiveSheet.Paste
End If
Next


But as I'm looking at the same data in Sh1. Can this be made shorter by
some
sort of Or here If c.Value = "H1" Then

Something like if c.Value = "H1","H2","H3" then?

Thanks
Carl


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to make this code smaller


Untested:For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Or c.Value = "H2" Or c.Value = "H3" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut Sheets("UK").Rows(lr1 + 1)
End If
Next
or:For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Or c.Value = "H2" Or c.Value = "H3" Then
c.EntireRow.Cut Sheets("UK").Rows(sh2.Range("A" &
Rows.Count).End(xlUp).Row + 1)
Next
Result won't necessarily be in the same order.
In both snippets I've tried shortening you cut/paste - again untested.


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=131534

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default How to make this code smaller

Thanks to all for replying.

Stefi's worked first time and tidied it up to where I needed it to be.

Many thanks
Carl

"p45cal" wrote:


Untested:For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Or c.Value = "H2" Or c.Value = "H3" Then
lr1 = sh2.Range("A" & Rows.Count).End(xlUp).Row
c.EntireRow.Cut Sheets("UK").Rows(lr1 + 1)
End If
Next
or:For Each c In sh1.Range("A1:A" & lr2)
If c.Value = "H1" Or c.Value = "H2" Or c.Value = "H3" Then
c.EntireRow.Cut Sheets("UK").Rows(sh2.Range("A" &
Rows.Count).End(xlUp).Row + 1)
Next
Result won't necessarily be in the same order.
In both snippets I've tried shortening you cut/paste - again untested.


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=131534




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
How do you make cells smaller? brawl Charts and Charting in Excel 4 April 5th 23 02:44 PM
Make ribbon Icons smaller cmenlale Excel Discussion (Misc queries) 1 September 4th 08 03:33 PM
How do I size a worksheet ? ( make smaller ) MartyH Excel Discussion (Misc queries) 5 May 31st 07 06:45 PM
How to split worksheet to make smaller Ltl Doc Excel Worksheet Functions 1 April 5th 06 08:14 AM
Make Values Smaller Q John Excel Worksheet Functions 1 December 14th 04 03:40 PM


All times are GMT +1. The time now is 03:19 AM.

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"