VLOOKUP并在同一工作表中搜索不同的n

时间:2019-04-26 15:46:50

标签: excel vba

[已编辑] 很抱歉,我没有对此做清楚的描述: 我的问题是关于VLookup函数: 我使用的代码如下:

    B5'n$CX$"

目的是让VBA转至B5工作表并确定哪个 “ n”(n25,n35等),必须去。

这没有用,所以我在这里寻求是否有任何建议。

以下是原始帖子:

我是VBA的新手,刚接触过一两次。 我修改了如下代码,我的目标是让 VBA根据“ DE”&i的值找到“ DI”&i的值 在电子表格B5中,但在B5中,数字“ n”取决于 “ CX”&i的值,然后在VBA查找“ DE”&i的值时, 它必须首先借助值确定n的值 “ CX”&i。 工作表B5的屏幕截图如下:

https://www.dropbox.com/s/do6i7zeylaz0sch/B5.jpg?dl=0

我的代码如下:

首先,如果“ DE”&i> 3.9,我希望VBA设置“ DI”&i = 0, 否则带有vlookup函数。 非常感谢您的帮助和建议。 赞赏。

    Sub FindPl()
    For i = 2 To 1730
    If .Cells("DE" & i).Value > 3.9 Then .Cells("DI" & i).Value = 0
    Else: .Cells("DI" & i).Value = 
    Application.WorksheetFunction.VLookup($DE$" & 
    i&",'[C:\Users\chenj5\Documents\Meeting_Jan_2019\simulation of Z1.9 for 
    Ultra Multi-Focal\Meeting 0220\Dataset used for simulation]B5'n$CX$" & 
    i&", 2, True)
    End If
    Next cell
    Next i
    End Sub

1 个答案:

答案 0 :(得分:0)

将尝试一些示例代码...我猜您的源数据并修复了一些语法错误...花了一些时间进行更新和适当确定尺寸。您发布的代码太多了/出错,无法提供更多清晰的信息。

library(shiny)
library(shiny.semantic)
library(semantic.dashboard)
library(ggplot2)
library(plotly)
library(DT)

ui <- dashboardPage(
  dashboardHeader(
    dropdownMenuOutput("dropdown"),
    dropdownMenu(type = "notifications",
                 taskItem("Project progress...", 50.777, color = "red")),
    dropdownMenu(
      icon = uiicon("red warning sign"),
      notificationItem("This is an important notification!", color = "red")
    )
  ),
  dashboardSidebar(side = "left",
                   sidebarMenu(
                     menuItem(
                       tabName = "plot_tab",
                       text = "My plot",
                       icon = icon("home")
                     ),
                     menuItem(
                       tabName = "table_tab",
                       text = "My table",
                       icon = icon("smile")
                     )
                   )),
  dashboardBody(tabItems(
    tabItem(tabName = "plot_tab",
            fluidRow(
              valueBox(
                "Unread Mail",
                44,
                icon("mail"),
                color = "blue",
                width = 5
              )
            ),
            fluidRow(
              box(
                title = "Sample box",
                color = "blue",
                width = 11,
                selectInput(
                  inputId =  "variable1",
                  choices = names(mtcars),
                  label = "Select first variable",
                  selected = "mpg"
                ),
                selectInput(
                  inputId =  "variable2",
                  choices = names(mtcars),
                  label = "Select second variable",
                  selected = "cyl"
                ),
                plotlyOutput("mtcars_plot")
              ),
              tabBox(
                title = "Sample box",
                color = "blue",
                width = 5,
                collapsible = FALSE,
                tabs = list(
                  list(menu = "First Tab", content = "Some text..."),
                  list(menu = "Second Tab", content = plotlyOutput("mtcars_plot2"))
                )
              )
            )),
    tabItem(
      tabName = "table_tab",
      fluidRow(
        valueBox(
          "Unread Mail",
          144,
          icon("mail"),
          color = "blue",
          width = 6,
          size = "small"
        ),
        valueBox(
          "Spam",
          20,
          icon("mail"),
          color = "red",
          width = 5,
          size = "small"
        ),
        valueBox(
          "Readed Mail",
          666,
          icon("mail"),
          color = "green",
          width = 5,
          size = "small"
        )
      ),
      fluidRow(
        box(
          title = "Classic box",
          color = "blue",
          ribbon = FALSE,
          title_side = "top left",
          width = 14,
          tags$div(
            dataTableOutput("mtcars_table")
            ,
            style = paste0("color:", semantic_palette[["blue"]], ";")
          )
        )
      )
    )
  )),
  theme = "slate"
)

server <- function(input, output) {
  output$mtcars_plot <-
    renderPlotly(plot_ly(
      mtcars,
      x = ~ mtcars[, input$variable1],
      y = ~ mtcars[, input$variable2],
      type = "scatter",
      mode = "markers"
    ))
  output$mtcars_plot2 <-
    renderPlotly(plot_ly(
      mtcars,
      x = ~ mtcars[, input$variable1],
      y = ~ mtcars[, input$variable2],
      type = "scatter",
      mode = "markers"
    ))

  output$mtcars_table <-
    renderDataTable(mtcars, options = list(dom = 't'))

  output$dropdown <- renderDropdownMenu({
    dropdownMenu(
      messageItem("User", "Test message", color = "teal", style = "min-width: 200px"),
      messageItem("Users", "Test message", color = "teal", icon = "users"),
      messageItem(
        "See this",
        "Another test",
        icon = "warning",
        color = "red"
      )
    )
  })
}

shinyApp(ui, server)