multiple actions based on one "if then" in VBA

patricknord

New Member
Joined
Apr 1, 2013
Messages
5
Hi,

I am trying to write a script that will return multiple actions if a condition is true--I wrote this and it is not working:

Sub test()


Dim currcell, mycell As Range

Set currcell = ActiveCell
Set mycell = Sheets("sheet2").Range("c5")

If (mycell.Value = Empty) Then mycell.Value = currcell And Sheet2.Cells(mycell.Row, mycell.Column + 1).Value = Sheet1.Cells(currcell.Row, currcell.Column + 1) _
Else: If (mycell = currcell) Then Sheet2.Cells(mycell.Row, mycell.Column + 1).Value = Sheet1.Cells(currcell.Row, currcell.Column + 1) * 2



End Sub

What do I need to change??
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Code:
Dim currcell, mycell As Range

Set currcell = ActiveCell
Set mycell = Sheets("sheet2").Range("c5")

If (mycell.Value = Empty) Then 

mycell.Value = currcell 
 
Sheet2.Cells(mycell.Row, mycell.Column + 1).Value = Sheet1.Cells(currcell.Row,currcell.Column + 1) 

ElseIf (mycell = currcell) Then

 Sheet2.Cells(mycell.Row, mycell.Column + 1).Value = Sheet1.Cells(currcell.Row,currcell.Column + 1) * 2

End If
 
Upvote 0
You should also look into using OFFSET

<COLGROUP><COL style="WIDTH: 48pt" width=64><TBODY>
</TBODY>
 
Upvote 0
Hi Guys ,

i need to copy the contend of multiple sheets to a new sheet.

To be more precise , i need to copy from each sheet( there are a few exceptions) the content of a single cell ("B8") and the range("A128:H188") and put them in a new sheet.("Installation details")

And i am stuck, i cannot copy both it's either the single cell or the range.


Sub Summarizeinstallationdetails()
Dim ws As Worksheet

Application.ScreenUpdating = False
Sheets("Installation details").Activate

Worksheets("Installation details").Range("A2:I200").EntireRow.Delete 'clean Installation details sheet

For Each ws In Worksheets
'Only look in to the country sheets meaning excluding all other sheeting, also exluding Russia as this is a seperate contract
If ws.Name <> "Installation details" And ws.Name <> "Facts" And ws.Name <> "Central Prices" _
And ws.Name <> "Telecom Equipment Prices" And ws.Name <> "Installation Prices" _
And ws.Name <> "InfraStructure Prices" And ws.Name <> "Local Prices" _
And ws.Name <> "CENTRAL" And ws.Name <> "Summary" _
And ws.Name <> "Russia" And ws.Name <> "Telia Invoice details" Then
ws.Range ("B8")
And ws.Range("A128:H188").Copy
Worksheets("Installation details").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)


End If
Next ws


End Sub

Many Thanks
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top