![](/img/trans.png)
[英]Copy and paste data from one sheet to another sheet(s) based on cell value
[英]Copy data from one cell to a cell in another sheet based on the value of a second cell in the first sheet?
我試圖根據第三個單元格的值(“是”或空白)將一個工作表中一個單元格的值復制到另一工作表中的單元格。 例:
Cell A1: Monday
Cell B1: Yes
如果B1 = Yes
則將單元格A1
的值復制到sheet2單元格B5
。 如果單元格B2
為空(或“否”),則什么也不做。 這可能嗎?
我試圖通過使用if語句來做到這一點,但沒有任何運氣。
[編輯]這是我的代碼(但尚無法使用):
Sub ColorWhite()
Range("B01:B15").Value = Yes
With Selection.Font
.ThemeColor = x1ThemeColorDark1
.TintAndShade = 0
End
Range("B01:B15").Value Not Yes
Selection.EntireRow.Hidden = True
End Sub
您可以在Sheet2的單元格B5上嘗試使用此公式
IF(Sheet1!B1 = "Yes", A1, "")
如果你想同時檢查B1 = Yes
並 nothing
或 No
在B2
:
IF(AND(Sheet1!B1 = "Yes", OR(Sheet1!B2 = "", Sheet1!B2="No")), A1, "")
並將其拖放到需要的范圍內
[編輯]這是根據您的評論進行的VBA嘗試。 我將其保持簡單(這樣做會更有效),以便易於理解和適應:
Sub ColorWhite()
Dim c As Range
For Each c In Worksheets("Sheet1").Range("B1:B15")
If c.Value = "Yes" Then
With Worksheets("Sheet2").Range(c.Address).Offset(0, -1)
.Value = Worksheets("Sheet1").Range(c.Address).Offset(0, -1).Value
With .Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
End With
End If
Next c
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.